home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 71.zip / BS1 part 71 / AmosPro2.0_d5.adf / Extensions / |Music.s < prev    next >
Text File  |  1992-09-28  |  95KB  |  4,615 lines

  1.  
  2. ;---------------------------------------------------------------------
  3. ;    **   **   **  ***   ***   ****     **    ***  **  ****
  4. ;   ****  *** *** ** ** **     ** **   ****  **    ** **  **
  5. ;  **  ** ** * ** ** **  ***   *****  **  **  ***  ** **
  6. ;  ****** **   ** ** **    **  **  ** ******    ** ** **
  7. ;  **  ** **   ** ** ** *  **  **  ** **  ** *  ** ** **  **
  8. ;  **  ** **   **  ***   ***   *****  **  **  ***  **  ****
  9. ;---------------------------------------------------------------------
  10. ; Music extension source code for AMOSPro, Last change 29/09/1992
  11. ; By Francois Lionet
  12. ; AMOS, AMOSPro AMOS Compiler (c) Europress Software 1990-1992
  13. ; To be used with AMOSPro 1.0 and over
  14. ;--------------------------------------------------------------------- 
  15. ; This file is public domain
  16. ;---------------------------------------------------------------------
  17. ;
  18. Version        MACRO
  19.         dc.b    "1.0"
  20.         ENDM
  21. ;
  22. ;
  23. ; This listing explains how to create an extension for AMOSPro.
  24. ; The AMOSPro compiler will be compatible with these extension.
  25. ;
  26. ;    If you have made an extension for AMOS 1.3, just read the
  27. ; file called New_In_Pro.Asc to know the difference between the
  28. ; extension format. Not many changes, only new equates, and some
  29. ; new functions.
  30. ;
  31. ; >>> What's an extension?
  32. ;
  33. ; An extension to AMOS is a machine language program that adds new 
  34. ; instructions to the already huge AMOS instruction set. This system is
  35. ; designed to be as powerfull as AMOS itself: the extension includes its 
  36. ; own token list, its own routines. It can even access some main AMOS
  37. ; routines via special macros. It has a total access to the internal AMOS 
  38. ; data zone, and to the graphic library functions.
  39. ;
  40. ; To produce your own extension, I suggest you copy and rename this
  41. ; file, and remove the used code. This way you will not forgive one line.
  42. ; Also keep in mind that you can perfectly call AMOS from within MONAM2,
  43. ; and set some ILLEGAL instructions where you want to debug. To flip back to
  44. ; MONAM2 display, just press AMIGA-A.
  45. ;
  46. ; I have designed the extension system so that one only file works with 
  47. ; both AMOS interpretor and compiler. 
  48. ;     - The extension is more a compiler library than a one chunk program:
  49. ;    it is done so that the compiler can pick one routine here and there
  50. ;    to cope with the program it is compiling.
  51. ;    - AMOSPro extension loader works a little like the compiler, exept
  52. ;    that all instructions are loaded and relocated.
  53. ;
  54. ; This code was assembled with GENIM2 on a A3000 25 Mhz machine, but a
  55. ; A500 can do it very well!
  56. ; The assembled program must be ONE CHUNK only, you must not link the 
  57. ; the symbol table with it. Also be sure that you program is totally 
  58. ; relocatable (see later) : if not it will add a relocation chunk to 
  59. ; the output code, and your extension will simply crash AMOS on loading
  60. ; (and the compiler too!).
  61.  
  62. ;
  63. ; Here we go now!
  64. ;
  65. ; Here comes the number of the extension in the list of extensions in
  66. ; AMOSPro_Interpretor_Config program (minus one).
  67. ; This number is used later to reference the extension in internal AMOS 
  68. ; tables...
  69. ;
  70. ExtNb        equ    1-1
  71.  
  72. ; You must include this file, it will decalre everything for you.
  73.         Include    "|AMOS_Includes.s"
  74. ; A usefull macro to find the address of data in the extension's own 
  75. ; datazone (see later)...
  76. DLea        MACRO
  77.         move.l    ExtAdr+ExtNb*16(a5),\2
  78.         add.w    #\1-MB,\2
  79.         ENDM
  80.  
  81. ; Another macro to load the base address of the datazone...
  82. DLoad        MACRO
  83.         move.l    ExtAdr+ExtNb*16(a5),\1
  84.         ENDM
  85.  
  86. ; Now some equates used by the music extension itself. Ignore this in your
  87. ; code!
  88.  
  89. Translate    equ -30
  90.  
  91. *************** Enveloppes definitions
  92.         RsReset
  93. EnvNb:        rs.w    1
  94. EnvDVol:    rs.w    1
  95. EnvVol:        rs.l    1
  96. EnvDelta:    rs.l     1
  97. EnvAd:        rs.l    1
  98. EnvDeb:        rs.l    1
  99. EnvLong:    equ     __Rs
  100.  
  101. *************** Wave definition
  102. LWave:        equ     256+128+64+32+16+8+4+2
  103. LNoise:        equ     LWave
  104.         RsReset
  105. WaveNext:    rs.l    1
  106. WaveNb:        rs.w    1
  107. WaveEnv:    rs.w    16*2
  108. WaveDeb:    rs.b    LWave
  109. WaveLong:    equ     __Rs
  110.  
  111. *************** Music voice data
  112.         RsReset
  113. VoiAdr        rs.l    1
  114. VoiDeb        rs.l    1
  115. VoiInst        rs.l    1
  116. VoiDPat        rs.l    1
  117. VoiPat        rs.l    1
  118. VoiCpt        rs.w    1
  119. VoiRep        rs.w    1
  120. VoiNote        rs.w    1
  121. VoiDVol        rs.w    1
  122. VoiVol        rs.w    1
  123. VoiEffect    rs.l    1
  124. VoiValue    rs.w    1
  125. VoiPToTo    rs.w    1
  126. VoiPTone    rs.b    1
  127. VoiVib        rs.b    1
  128. VoiLong        equ     __Rs
  129.  
  130. *************** MUBASE table
  131.         RsReset
  132. * Voix 0
  133. MuVoix0        equ    __Rs
  134. VoiAdr0        rs.l    1
  135. VoiDeb0        rs.l    1
  136. VoiInst0    rs.l    1
  137. VoiDPat0    rs.l    1
  138. VoiPat0        rs.l    1
  139. VoiCpt0        rs.w    1
  140. VoiRep0        rs.w    1
  141. VoiNote0    rs.w    1
  142. VoiDVol0    rs.w    1
  143. VoiVol0        rs.w    1
  144. VoiEffect0    rs.l    1
  145. VoiValue0    rs.w    1
  146. VoiPToTo0    rs.w    1
  147. VoiPTone0    rs.b    1
  148. VoiVib0        rs.b    1
  149. * Voix 1
  150. MuVoix1        equ    __Rs
  151. VoiAdr1        rs.l    1
  152. VoiDeb1        rs.l    1
  153. VoiInst1    rs.l    1
  154. VoiDPat1    rs.l    1
  155. VoiPat1        rs.l    1
  156. VoiCpt1        rs.w    1
  157. VoiRep1        rs.w    1
  158. VoiNote1    rs.w    1
  159. VoiDVol1    rs.w    1
  160. VoiVol1        rs.w    1
  161. VoiEffect1    rs.l    1
  162. VoiValue1    rs.w    1
  163. VoiPToTo1    rs.w    1
  164. VoiPTone1    rs.b    1
  165. VoiVib1        rs.b    1
  166. * Voix 2
  167. MuVoix2        equ    __Rs
  168. VoiAdr2        rs.l    1
  169. VoiDeb2        rs.l    1
  170. VoiInst2    rs.l    1
  171. VoiDPat2    rs.l    1
  172. VoiPat2        rs.l    1
  173. VoiCpt2        rs.w    1
  174. VoiRep2        rs.w    1
  175. VoiNote2    rs.w    1
  176. VoiDVol2    rs.w    1
  177. VoiVol2        rs.w    1
  178. VoiEffect2    rs.l    1
  179. VoiValue2    rs.w    1
  180. VoiPToTo2    rs.w    1
  181. VoiPTone2    rs.b    1
  182. VoiVib2        rs.b    1
  183. * Voix 3
  184. MuVoix3        equ    __Rs
  185. VoiAdr3        rs.l    1
  186. VoiDeb3        rs.l    1
  187. VoiInst3    rs.l    1
  188. VoiDPat3    rs.l    1
  189. VoiPat3        rs.l    1
  190. VoiCpt3        rs.w    1
  191. VoiRep3        rs.w    1
  192. VoiNote3    rs.w    1
  193. VoiDVol3    rs.w    1
  194. VoiVol3        rs.w    1
  195. VoiEffect3    rs.l    1
  196. VoiValue3    rs.w    1
  197. VoiPToTo3    rs.w    1
  198. VoiPTone3    rs.b    1
  199. VoiVib3        rs.b    1
  200.  
  201. * Other data
  202. MuCpt        rs.w    1
  203. MuTempo        rs.w    1
  204. MuStart        rs.w    1
  205. MuStop        rs.w    1
  206. * Total length
  207. MuLong        equ     __Rs
  208.  
  209. IntEnaR        equ    $1c
  210. IntReqR        equ    $1e
  211. is_data        equ    $0e
  212. is_code        equ    $12
  213. ln_pri        equ    $09
  214. ln_type        equ    $08
  215.  
  216. ; All the above did not produce any byte of code. Here is the real beginning
  217. ; of the program. It MUST begin by a small table of pointers so that both
  218. ; AMOS and the compiler know where to get their data...
  219. ; Please remark that everything is relocatable...
  220.  
  221. ******************************************************************
  222. *    AMOSPro MUSIC EXTENSION
  223. ;
  224. ; First, a pointer to the token list
  225. Start    dc.l    C_Tk-C_Off
  226. ;
  227. ; Then, a pointer to the first library function
  228.     dc.l    C_Lib-C_Tk
  229. ;
  230. ; Then to the title
  231.     dc.l    C_Title-C_Lib
  232. ;
  233. ; From title to the end of the program
  234.     dc.l    C_End-C_Title
  235. ;
  236. ; An important flag. Imagine a program does not call your extension, the 
  237. ; compiler will NOT copy any routine from it in the object program. For 
  238. ; certain extensions, like MUSIC, COMPACT, it is perfect.
  239. ; But for the REQUEST extension, even if it is not called, the first routine 
  240. ; MUST be called, otherwise AMOS requester will not work!
  241. ; So, a value of 0 indicates to copy if needed only,
  242. ; A value of -1 forces the copy of the first library routine...
  243.     dc.w    0    
  244.  
  245. ******************************************************************
  246. *    Offset to library
  247. ;
  248. ; This list contains all informations for the compiler 
  249. ; and AMOS to locate your routines, in a relocatable way.
  250. ; You can produce such tables using the MAKE_LABEL.AMOS utility, found 
  251. ; on this very disc.
  252. ; All labels MUST be in order. The size of each routine MUST BE EVEN,
  253. ; as the size is divided by two. So be carefull to put an EVEN instruction
  254. ; after some text...
  255. ; You easily understand that the size of each routine can reach 128K, 
  256. ; which is largely enough. You can have up to 2000 routines in the list.
  257. ; The main AMOS.Lib library has 1100 labels...
  258.  
  259. C_Off   dc.w (L1-L0)/2,(L2-L1)/2,(L3-L2)/2,(L4-L3)/2
  260.         dc.w (L5-L4)/2,(L6-L5)/2,(L7-L6)/2,(L8-L7)/2
  261.         dc.w (L9-L8)/2,(L10-L9)/2,(L11-L10)/2,(L12-L11)/2
  262.         dc.w (L13-L12)/2,(L14-L13)/2,(L15-L14)/2,(L16-L15)/2
  263.         dc.w (L17-L16)/2,(L18-L17)/2,(L19-L18)/2,(L20-L19)/2
  264.         dc.w (L21-L20)/2,(L22-L21)/2,(L23-L22)/2,(L24-L23)/2
  265.         dc.w (L25-L24)/2,(L26-L25)/2,(L27-L26)/2,(L28-L27)/2
  266.         dc.w (L29-L28)/2,(L30-L29)/2,(L31-L30)/2,(L32-L31)/2
  267.         dc.w (L33-L32)/2,(L34-L33)/2,(L35-L34)/2,(L36-L35)/2
  268.         dc.w (L37-L36)/2,(L38-L37)/2,(L39-L38)/2,(L40-L39)/2
  269.         dc.w (L41-L40)/2,(L42-L41)/2,(L43-L42)/2,(L44-L43)/2
  270.         dc.w (L45-L44)/2,(L46-L45)/2,(L47-L46)/2,(L48-L47)/2
  271.         dc.w (L49-L48)/2,(L50-L49)/2,(L51-L50)/2,(L52-L51)/2
  272.         dc.w (L53-L52)/2,(L54-L53)/2,(L55-L54)/2,(L56-L55)/2
  273.         dc.w (L57-L56)/2,(L58-L57)/2,(L59-L58)/2,(L60-L59)/2
  274.         dc.w (L61-L60)/2,(L62-L61)/2,(L63-L62)/2,(L64-L63)/2
  275.         dc.w (L65-L64)/2,(L66-L65)/2,(L67-L66)/2,(L68-L67)/2
  276.         dc.w (L69-L68)/2,(L70-L69)/2,(L71-L70)/2,(L72-L71)/2
  277.         dc.w (L73-L72)/2,(L74-L73)/2,(L75-L74)/2,(L76-L75)/2
  278.         dc.w (L77-L76)/2,(L78-L77)/2,(L79-L78)/2,(L80-L79)/2
  279.         dc.w (L81-L80)/2,(L82-L81)/2,(L83-L82)/2,(L84-L83)/2
  280.         dc.w (L85-L84)/2,(L86-L85)/2,(L87-L86)/2,(L88-L87)/2
  281.     dc.w (L89-L88)/2,(L90-L89)/2,(L91-L90)/2,(L92-L91)/2
  282.         dc.w (L93-L92)/2,(L94-L93)/2,(L95-L94)/2,(L96-L95)/2
  283.         dc.w (L97-L96)/2,(L98-L97)/2,(L99-L98)/2,(L100-L99)/2
  284.         dc.w (L101-L100)/2,(L102-L101)/2,(L103-L102)/2,(L104-L103)/2
  285.         dc.w (L105-L104)/2,(L106-L105)/2,(L107-L106)/2,(L108-L107)/2
  286.         dc.w (L109-L108)/2,(L110-L109)/2,(L111-L110)/2,(L112-L111)/2
  287.     dc.w (L113-L112)/2,(L114-L113)/2
  288.  
  289. ; Do not forget the LAST label!!!
  290.  
  291. ******************************************************************
  292. *    TOKEN TABLE
  293. ;
  294. ;
  295. ;    
  296. ; This table is the crucial point of the extension! It tells
  297. ; everything the tokenisation process needs to know. You have to 
  298. ; be carefull when writing it!
  299. ;
  300. ; The format is simple:
  301. ;    dc.w    Number of instruction,Number of function
  302. ;    dc.b    "instruction nam","e"+$80,"Param list",-1[or -2]
  303. ;
  304. ;    (1) Number of instruction / function
  305. ;        You must state the one that is needed for this token.
  306. ;               I suggest you keep the same method of referencing the
  307. ;        routines than mine: L_name, this label being defined
  308. ;        in the main program. (If you come from a 1.23 extension,
  309. ;        changing your program is easy: just add L_ before the 
  310. ;        name of each routine.
  311. ;        A -1 means take no routine is called (example a 
  312. ;        instruction only will have a -1 in the function space...)
  313. ;
  314. ;    (2) Instruction name
  315. ;        It must be finished by the letter plus $80. Be carefull
  316. ;        ARGASM assembler produces bad code if you do "a"+$80, 
  317. ;        he wants $80+"a"!!!
  318. ;        - You can SET A MARK in the token table with a "!" before
  319. ;        the name. See later
  320. ;        -Using a $80 ALONE as a name definition, will force AMOS
  321. ;        to point to the previous "!" mark...
  322. ;    
  323. ;    (3) Param list
  324. ;        This list tells AMOS everything about the instruction.
  325. ;
  326. ;    - First character:
  327. ;        The first character defines the TYPE on instruction:
  328. ;            I--> instruction
  329. ;            0--> function that returns a integer
  330. ;            1--> function that returns a float
  331. ;            2--> function that returns a string
  332. ;            V--> reserved variable. In that case, you must
  333. ;                state the type int-float-string
  334. ;    - If your instruction does not need parameters, then you stop
  335. ;    - Your instruction needs parameters, now comes the param list
  336. ;            Type,TypetType,Type...
  337. ;        Type of the parameter (0 1 2)
  338. ;        Comma or "t" for TO
  339. ;
  340. ;    (4) End of instruction
  341. ;            "-1" states the end of the instruction
  342. ;            "-2" tells AMOS that another parameter list
  343. ;                 can be accepted. if so, MUST follow the
  344. ;                 complete instruction definition as explained
  345. ;                 but with another param list.
  346. ;    If so, you can use the "!" and $80 facility not to rewrite the
  347. ;    full name of the instruction...See SAM LOOP ON instruction for an
  348. ;    example...
  349. ;
  350. ;    Remember that AMOS token list comes first, so names like:
  351. ;    PRINTHELLO will never work: AMOS will tokenise PRINT first!
  352. ;    Extension token list are explored in order of number...
  353.  
  354. ; The next two lines needs to be unchanged...
  355. C_Tk:    dc.w     1,0
  356.     dc.b     $80,-1
  357.  
  358. ; Now the real tokens...
  359.     dc.w    -1,L_FMB
  360.     dc.b    "mubas","e"+$80,"0",-1
  361.     dc.w    -1,L_FVu
  362.     dc.b    "vumete","r"+$80,"00",-1
  363.     dc.w    L_IVoice,-1
  364.     dc.b    "voic","e"+$80,"I0",-1
  365.     dc.w    L_IMusOff,-1
  366.     dc.b    "music of","f"+$80,"I",-1
  367.     dc.w    L_IMuStop,-1
  368.     dc.b    "music sto","p"+$80,"I",-1
  369.     dc.w    L_ITempo,-1
  370.     dc.b    "temp","o"+$80,"I0",-1
  371.     dc.w    L_IMusic,-1
  372.     dc.b    "musi","c"+$80,"I0",-1
  373.  
  374.     dc.w    L_INoTo,-1
  375.     dc.b    "noise t","o"+$80,"I0",-1
  376.     dc.w    L_Boom,-1
  377.     dc.b     "boo","m"+$80,"I",-1
  378.     dc.w    L_Shoot,-1
  379.     dc.b    "shoo","t"+$80,"I",-1
  380.     dc.w    L_ISBank,-1
  381.     dc.b    "sam ban","k"+$80,"I0",-1
  382.     dc.w    L_ISLOn0,-1
  383.     dc.b    "!sam loop o","n"+$80,"I",-2
  384.     dc.w    L_ISLOn1,-1
  385.     dc.b    $80,"I",-1
  386.     dc.w    L_ISLOf0,-1
  387.     dc.b    "sam loop of","f"+$80,"I",-2
  388.     dc.w    L_ISLOf1,-1
  389.     dc.b    $80,"I0",-1
  390.     dc.w    L_ISamTo,-1
  391.     dc.b    "sampl","e"+$80,"I0t0",-1
  392.     dc.w     L_ISam1,-1
  393.     dc.b     "!sam pla","y"+$80,"I0",-2
  394.     dc.w    L_ISam2,-1
  395.     dc.b    $80,"I0,0",-2
  396.     dc.w     L_ISam3,-1
  397.     dc.b    $80,"I0,0,0",-1 
  398.     dc.w     L_ISamR,-1
  399.     dc.b     "sam ra","w"+$80,"I0,0,0,0",-1    
  400.     dc.w    L_Bell0,-1
  401.     dc.b     "!bel","l"+$80,"I",-2
  402.     dc.w     L_Bell1,-1
  403.     dc.b    $80,"I0",-1
  404.     dc.w    L_IPlOf0,-1
  405.     dc.b    "!play of","f"+$80,"I",-2
  406.     dc.w    L_IPlOf1,-1
  407.     dc.b    $80,"I0",-1
  408.     dc.w     L_IPlay2,-1
  409.     dc.b    "!pla","y"+$80,"I0,0",-2
  410.     dc.w    L_IPlay3,-1
  411.     dc.b    $80,"I0,0,0",-1
  412.     dc.w     L_ISWave,-1
  413.     dc.b     "set wav","e"+$80,"I0,2",-1
  414.     dc.w    L_IDWave1,-1
  415.     dc.b    "del wav","e"+$80,"I0",-1
  416.     dc.w    L_ISEnv,-1
  417.     dc.b    "set enve","l"+$80,"I0,0t0,0",-1
  418.     dc.w    L_IMVol,-1
  419.     dc.b    "mvolum","e"+$80,"I0",-1
  420.     dc.w     L_IVol1,-1
  421.     dc.b    "!volum","e"+$80,"I0",-2
  422.     dc.w     L_IVol2,-1
  423.     dc.b    $80,"I0,0",-1
  424.     dc.w    L_IWave,-1
  425.     dc.b     "wav","e"+$80,"I0t0",-1
  426.     dc.w    L_LedOn,-1
  427.     dc.b    "led o","n"+$80,"I",-1
  428.     dc.w    L_LedOf,-1
  429.     dc.b    "led of","f"+$80,"I",-1
  430.     dc.w    L_ISay1,-1
  431.     dc.b    "!sa","y"+$80,"I2",-2
  432.     dc.w    L_ISay2,-1
  433.     dc.b    $80,"I2,0",-1
  434.     dc.w    L_ITalk,-1
  435.     dc.b    "set tal","k"+$80,"I0,0,0,0",-1
  436.     dc.w    L_SLoad,-1
  437.     dc.b    "sloa","d"+$80,"I0t0,0",-1
  438.     dc.w    -1,L_Samswapped
  439.     dc.b    "sam swappe","d"+$80,"00",-1
  440.     dc.w    L_SamSwap,-1
  441.     dc.b    "sam swa","p"+$80,"I0t0,0",-1
  442.     dc.w     L_SamStop0,-1
  443.     dc.b    "!sam sto","p"+$80,"I",-2
  444.     dc.w    L_SamStop1,-1
  445.     dc.b    $80,"I0",-1
  446.  
  447.     dc.w    L_TrackStop,-1
  448.     dc.b    "track sto","p"+$80,"I",-1
  449.     dc.w    L_TrackLoopon,-1
  450.     dc.b    "track loop o","n"+$80,"I",-1
  451.     dc.w    L_TrackLoopof,-1
  452.     dc.b    "track loop o","f"+$80,"I",-1
  453.     dc.w    L_TrackPlay0,-1
  454.     dc.b    "!track pla","y"+$80,"I",-2
  455.     dc.w    L_TrackPlay1,-1
  456.     dc.b    $80,"I0",-2
  457.     dc.w    L_TrackPlay2,-1
  458.     dc.b    $80,"I0,0",-1
  459.     dc.w    L_TrackLoad,-1
  460.     dc.b    "track loa","d"+$80,"I2,0",-1
  461.     
  462.     dc.w    -1,L_LipsX
  463.     dc.b    "mouth widt","h"+$80,"0",-1
  464.     dc.w    -1,L_LipsY
  465.     dc.b    "mouth heigh","t"+$80,"0",-1
  466.     dc.w    L_Lips,-1
  467.     dc.b    "mouth rea","d"+$80,"I",-1
  468.     dc.w    L_NarStop,-1
  469.     dc.b    "talk sto","p"+$80,"I",-1
  470.     dc.w    L_TalkMisc,-1
  471.     dc.b    "talk mis","c"+$80,"I0,0",-1
  472.  
  473.     dc.w    L_SSave,-1
  474.     dc.b    "ssav","e"+$80,"I0,0t0",-1
  475.  
  476.     dc.w    L_MedLoad,-1
  477.     dc.b    "med loa","d"+$80,"I2,0",-1
  478.     dc.w    L_MedPlay0,-1
  479.     dc.b    "!med pla","y"+$80,"I",-2
  480.     dc.w    L_MedPlay1,-1
  481.     dc.b    $80,"I0",-2
  482.     dc.w    L_MedPlay2,-1
  483.     dc.b    $80,"I0,0",-1
  484.     dc.w    L_MedStop,-1
  485.     dc.b    "med sto","p"+$80,"I",-1
  486.     dc.w    L_MedCont,-1
  487.     dc.b    "med con","t"+$80,"I",-1
  488.     dc.w    L_MedMidiOn,-1
  489.     dc.b    "med midi o","n"+$80,"I",-1
  490.     dc.w     0
  491.  
  492. ;
  493. ; Now come the big part, the library. Every routine is delimited by the
  494. ; two labels: L(N) and L(N+1).
  495. ; AMOS loads the whole extension, but the compiler works differently:
  496. ; The compiler picks each routine in the library and copy it into the
  497. ; program, INDIVIDUALLY. It means that you MUST NEVER perform a JMP, a
  498. ; BSR or get an address from one library routine to another: the distance
  499. ; between them may change!!! Use the special macros instead...
  500. ;
  501. ; Importants points to follow: 
  502. ;
  503. ;    - Your code must be (pc), TOTALLY relocatable, check carefully your
  504. ;      code!
  505. ;    - You cannot directly call other library routines from one routine
  506. ;    by doing a BSR, but I have defined special macros (in S_CEQU file) 
  507. ;    to allow you to easily do so. Here is the list of available macros:
  508. ;
  509. ;    RBsr    L_Routine    does a simple BSR to the routine
  510. ;    RBra    L_Routine    as a normal BRA
  511. ;    RBeq    L_Routine    as a normal Beq
  512. ;    RBne    L_Routine    ...
  513. ;    RBcc    L_Routine
  514. ;    RBcs    L_Routine
  515. ;    RBlt    L_Routine
  516. ;    RBge    L_Routine
  517. ;    RBls    L_Routine
  518. ;    RBhi    L_Routine
  519. ;    RBle    L_Routine
  520. ;    RBpl    L_Routine
  521. ;    RBmi    L_Routine
  522. ;
  523. ; I remind you that you can only use this to call an library routine
  524. ; from ANOTHER routine. You cannot do a call WITHIN a routine, or call
  525. ; the number of the routine your caling from...
  526. ; The compiler (and AMOSPro extension loading part) will manage to find
  527. ; the good addresses in your program from the offset table.
  528. ;
  529. ; You can also call some main AMOS.Lib routines, to do so, use the 
  530. ; following macros:
  531. ;
  532. ;    RJsr    L_Routine    
  533. ;    RJmp    L_Routine    
  534. ; As you do not have access any more to the small table with jumps to the
  535. ; routines within AMOS, here is the concordance of the routines (the numbers
  536. ; are just refecrences to the old AMOS 1.23 calling table, and is not of
  537. ; any use in AMOS1.3):
  538. ;
  539. ;
  540. ;    RJsr    L_Error
  541. ; ~~~~~~~~~~~~~~~~~~~~~
  542. ;    Jump to normal error routine. See end of listing
  543. ;
  544. ;    RJsr    L_ErrorExt
  545. ; ~~~~~~~~~~~~~~~~~~~~~~~~
  546. ;    Jump to specific error routine. See end of listing.
  547. ;
  548. ;     RJsr    L_Tests
  549. ; ~~~~~~~~~~~~~~~~~~~~~
  550. ;    Perform one AMOSPro updating procedure, update screens, sprites,
  551. ;    bobs etc. You should use it for wait loops.
  552. ;
  553. ;    RJsr    L_WaitRout
  554. ; ~~~~~~~~~~~~~~~~~~~~~~~~
  555. ;    See play instruction.
  556. ;
  557. ;    RJsr    L_GetEc
  558. ; ~~~~~~~~~~~~~~~~~~~~~
  559. ;    Get screen address: In: D0.l= number, Out: A0=address
  560. ;
  561. ;    RJsr    L_Demande
  562. ; ~~~~~~~~~~~~~~~~~~~~~~~
  563. ;    Ask for string space.
  564. ;    D3.l is the length to ask for. Return A0/A1 point to free space.
  565. ;    Poke your string there, add the length of it to A0, EVEN the 
  566. ;    address to the highest multiple of two, and move it into
  567. ;    HICHAINE(a5) location...
  568. ;
  569. ;    RJsr    L_RamChip
  570. ; ~~~~~~~~~~~~~~~~~~~~~
  571. ;    Ask for PUBLIC|CLEAR|CHIP ram, size D0, return address in D0, nothing
  572. ;    changed, Z set according to the success.
  573. ;
  574. ;    RJsr    L_RamChip2
  575. ; ~~~~~~~~~~~~~~~~~~~~~~
  576. ;    Same for PUBLIC|CHIP
  577. ;
  578. ;    RJsr    L_RamFast
  579. ; ~~~~~~~~~~~~~~~~~~~~~
  580. ;    Same for PUBLIC|CLEAR
  581. ;
  582. ;    RJsr    L_RamFast2
  583. ; ~~~~~~~~~~~~~~~~~~~~~~~~
  584. ;    Same for PUBLIC
  585. ;
  586. ;    RJsr    L_RamFree
  587. ; ~~~~~~~~~~~~~~~~~~~~~~~
  588. ;    Free memory A1/D0
  589. ;
  590. ;    RJsr    L_Bnk.OrAdr
  591. ; ~~~~~~~~~~~~~~~~~~~~~~~~~
  592. ;    Find whether a number is a address or a    memory bank number
  593. ;    IN:     D0.l= number 
  594. ;    OUT:     D0/A0= number or start(number)
  595. ;
  596. ;    RJsr    L_Bnk.GetAdr
  597. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~
  598. ;    Find the start of a memory bank.
  599. ;    IN:    D0.l=    Bank number
  600. ;    OUT:    A0=    Bank address
  601. ;        D0.w=    Bank flags
  602. ;        Z set if bank not defined.
  603. ;
  604. ;    RJsr    L_Bnk.GetBobs
  605. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  606. ;    Returns the address of the bob's bank
  607. ;    IN:
  608. ;    OUT:    Z     Set if not defined
  609. ;        A0=    address of bank
  610. ;
  611. ;    RJsr    L_Bnk.GetIcons
  612. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  613. ;    Returns the address of the icons bank
  614. ;    IN:
  615. ;    OUT:    Z     Set if not defined
  616. ;        A0=    address of bank
  617. ;
  618. ;    RJsr    L_Bnk.Reserve
  619. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  620. ;    Reserve a memory bank.
  621. ;    IN:    D0.l    Number
  622. ;        D1    Flags
  623. ;        D2    Length
  624. ;        A0    Name of the bank (8 bytes)
  625. ;    OUT:    Z     Set inf not successfull
  626. ;        A0    Address of bank
  627. ;    FLAGS:    
  628. ;        Bnk_BitData        Data bank
  629. ;        Bnk_BitChip        Chip bank
  630. ;        Example:    Bset    #Bnk_BitData|Bnk_BitChip,d1
  631. ;    NOTE:     you should call L_Bnk.Change after reserving/erasing a bank.
  632. ;
  633. ;    RJsr    L_Bnk.Eff
  634. ; ~~~~~~~~~~~~~~~~~~~~~~~
  635. ;    Erase one memory bank.
  636. ;    IN:    D0.l    Number
  637. ;    OUT:    
  638. ;
  639. ;    RJsr    L_Bnk.EffA0
  640. ; ~~~~~~~~~~~~~~~~~~~~~~~~~
  641. ;    Erase a bank from its address.
  642. ;    IN:    A0    Start(bank)
  643. ;    OUT:    
  644. ;
  645. ;    RJsr    L_Bnk.EffTemp
  646. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  647. ;    Erase all temporary banks
  648. ;    IN:
  649. ;    OUT:
  650. ;
  651. ;    RJsr    L_Bnk.EffAll
  652. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~
  653. ;    Erase all banks
  654. ;    IN:
  655. ;    OUT:
  656. ;
  657. ;    RJsr    L_Bnk.Change
  658. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~
  659. ;    Inform the extension, the bob handler that something has changed
  660. ;    in the banks. You should use this function after every bank
  661. ;    reserve / erase.
  662. ;    IN:
  663. ;    OUT:
  664. ;
  665. ;     RJsr    L_Dsk.PathIt
  666. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~
  667. ;    Add the current AMOS path to a file name.
  668. ;    IN:    (Name1(a5)) contains the name, finished by zero
  669. ;    OUT:    (Name1(a5)) contains the name with new path
  670. ;    Example:
  671. ;        move.l    Name1(a5),a0
  672. ;        move.l    #"Kiki",(a0)+
  673. ;        clr.b    (a0)
  674. ;        RJsr    L_Dsk.PathIt
  675. ;        ... now I load in the current directory
  676. ;
  677. ;    RJsr     L_Dsk.FileSelector
  678. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  679. ;    Call the file selector.
  680. ;    IN:    12(a3)    Path+filter
  681. ;        8(a3)    Default name
  682. ;        4(a3)    Title 2
  683. ;        0(a3)    Title 1
  684. ;        All strings must be in AMOS string format:
  685. ;            dc.w    Length
  686. ;            dc.b     "String"
  687. ;    OUT:    D0.w    Length of the result. 0 if no selection
  688. ;        A0    Address of first character of the result.
  689.  
  690. ;
  691. ;    HOW DOES IT WORK?
  692. ;
  693. ; Having a look at the |CEQU file, you see that I use special codes
  694. ; to show the compiler that it has to copy the asked routine and relocate
  695. ; the branch. Some remarks:
  696. ;    - The size of a Rbsr is 4 bytes, like the normal branch, it does
  697. ; not change the program (you can make some jumps over it)
  698. ;    - Although I have coded the signal, and put a lot a security, 
  699. ; a mischance may lead to the compiler thinking there is a RBsr where
  700. ; there is nothing than normal data. The result may be disastrous! So if
  701. ; you have BIG parts of datas in which you do not make any special calls,
  702. ; you can put before it the macro: RDATA. It tells the compiler that 
  703. ; the following code, up to the end of the library routine (up to the next
  704. ; L(N) label) is normal data: the compiler will not check for RBranches...
  705. ; Up to now, I have not been forced to do so, but if something goes wrong,
  706. ; try that!
  707. ;
  708. ;
  709.  
  710. C_Lib
  711. ******************************************************************
  712. *        COLD START
  713. *
  714. ; The first routine of the library will perform all initialisations in the
  715. ; booting of AMOS.
  716. ;
  717. ; I have put here all the music datazone, and all the interrupt routines.
  718. ; I suggest you put all you C-Code here too if you have some...
  719.  
  720. ; ALL the following code, from L0 to L1 will be copied into the compiled 
  721. ; program (if any music is used in the program) at once. All RBSR, RBRA etc
  722. ; will be detected and relocated. AMOSPro extension loader does the same.
  723.  
  724. L0    movem.l    a3-a6,-(sp)
  725. ;
  726. ; Here I store the address of the extension data zone in the special area
  727.     lea    MB(pc),a3
  728.     move.l    a3,ExtAdr+ExtNb*16(a5)
  729. ;
  730. ; Here, I store the address of the routine called by DEFAULT, or RUN
  731.     lea    MusDef(pc),a0
  732.     move.l    a0,ExtAdr+ExtNb*16+4(a5)
  733. ;
  734. ; Here, the address of the END routine,
  735.     lea    MusEnd(pc),a0
  736.     move.l    a0,ExtAdr+ExtNb*16+8(a5)
  737. ;
  738. ; And now the Bank check routine..
  739.     lea    BkCheck(pc),a0
  740.     move.l    a0,ExtAdr+ExtNb*16+12(a5)
  741.  
  742. ; You are not obliged to store something in the above areas, you can leave
  743. ; them to zero if no routine is to be called...
  744. ;
  745. ; In AMOS data zone, stands 8 long words allowing you to simply
  746. ; put a patch in the VBL interrupt. The first on is at VBLRout.
  747. ; At each VBL, AMOS explores this list, and call all address <> 0
  748. ; It stops at the FIRST zero. The music patch is the first routine
  749. ; called.
  750.  
  751.     lea    MusInt(pc),a0        * Interrupt routine
  752.     move.l    a0,VBLRout(a5)
  753. ; 50/60 herz?
  754.     move.l    #3546895,MusClock-MB(a3)
  755.     move.w    #100,TempoBase-MB(a3)
  756.     EcCall    NTSC            * Is system NTSC?
  757.     tst.w    d1
  758.     beq.s    ItsPAL
  759.     move.w    #120,TempoBase-MB(a3)
  760.     move.l    #3579545,MusClock-MB(a3)
  761. ItsPAL    
  762. ; Install sample interrupts
  763.     lea    Sami_handler(pc),a0
  764.     move.l    a0,Sami_handad-MB(a3)
  765.  
  766. ; As you can see, you MUST preserve A3-A6, and return in D0 the 
  767. ; Number of the extension if everything went allright. If an error has
  768. ; occured (no more memory, no file found etc...), return -1 in D0 and
  769. ; AMOS will refuse to start.
  770.     movem.l    (sp)+,a3-a6
  771.     moveq    #ExtNb,d0        * NO ERRORS
  772.      rts
  773.  
  774. ******* SCREEN RESET
  775. ; This routine is called each time a DEFAULT occurs...
  776. ;
  777. ; The next instruction loads the internal datazone address. I could have
  778. ; of course done a load MB(pc),a3 as the datazone is in the same
  779. ; library chunk. 
  780.  
  781. MusDef    DLoad    a3    
  782. * Stop/Init narrator
  783.     Rbsr    L_NarStop
  784.     Rbsr    L_NarInit
  785. * Reset TRACKER music
  786.     Rbsr    L_TrackStop
  787. * Reset MED music
  788.     Rbsr    L_MedClose
  789.     clr.b    Med_Midi-MB(a3)
  790. * Reset Sam_interrupts
  791.     move.w    #$000F,Circuits+DmaCon
  792.     Rbsr    L_Sami_install
  793. * Init musique
  794.     Rbsr    L_RazWave        * Reset waves
  795.     move.l    Buffer(a5),a0        * Draw square wave
  796.     move.l    a0,a1
  797.     moveq    #127,d0
  798. MuDf1    move.b    #-127,128(a0)
  799.     move.b    #127,(a0)+
  800.     dbra    d0,MuDf1
  801.     moveq    #0,d1            * 0-> Noise
  802.     Rbsr    L_NeWave
  803.     moveq    #1,d1            * 1-> Square wave
  804.     Rbsr    L_NeWave
  805.     move.w    #LNoise/2-1,d2        * Draw first noise
  806.     move.w    BSeed-MB(a3),d1
  807.     move.l    WaveBase-MB(a3),a0
  808.     lea    WaveDeb(a0),a0
  809. MuDf2    add.w    Circuits+6,d1
  810.     mulu    #$3171,d1
  811.     lsr.l    #8,d1
  812.     move.w    d1,(a0)+
  813.     dbra    d2,MuDf2
  814.     move.w    d1,BSeed-MB(a3)
  815.     moveq    #56,d0            * Default settings
  816.     moveq    #%1111,d1
  817.     Rbsr    L_Vol
  818.     Rbsr    L_MVol
  819.     move.w    #5,SamBank-MB(a3)    * Sample bank=5    
  820.     moveq    #-1,d0            * Sam loop off
  821.     moveq    #-1,d1
  822.     Rbsr    L_SL0
  823.     Rbra    L_MuInit
  824.  
  825. ******* QUIT
  826. ; This routine is called when you quit AMOS or when the compiled program
  827. ; ends. If you have opend devices, reserved memory you MUST close and
  828. ; restore everything to normal.
  829.  
  830. MusEnd:    DLoad    a3
  831.  
  832. ; Ferme le narrator
  833.     Rbsr    L_NarStop
  834.     move.l    $4.w,a6
  835.     move.l    WriteIo-MB(a3),d0
  836.     beq.s    .Skip1
  837.     move.l    d0,a1
  838.     move.l    WriteIo-MB(a3),a1
  839.     jsr    _LVOCloseDevice(a6)
  840. ; Enleve la structure
  841.     move.l    WriteIo-MB(a3),-(sp)
  842.     moveq    #3,d0
  843.     Rbsr    L_Amiga.Lib
  844.     addq.l    #4,sp
  845. ; Enleve les ports
  846.     move.l    WritePort-MB(a3),-(sp)
  847.     moveq    #1,d0
  848.     Rbsr    L_Amiga.Lib
  849.     addq.l    #4,sp
  850.     move.l    ReadPort-MB(a3),-(sp)
  851.     moveq    #1,d0
  852.     Rbsr    L_Amiga.Lib
  853.     addq.l    #4,sp
  854. ; Enleve le translator
  855. .Skip1    move.l    TranBase-MB(a3),d0
  856.     beq.s    NarEnd
  857.     move.l    d0,a1
  858.     jsr    CloseLib(a6)
  859. NarEnd    
  860. * No more TRACKER music
  861.     Rbsr    L_TrackStop
  862. * No more MED music
  863.     Rbsr    L_MedClose
  864. * No more VBL
  865.     clr.l    VBLRout(a5)
  866. * No more Sami
  867.     RBsr    L_Sami_remove
  868. * End music
  869.     Rbsr    L_MOff
  870.     moveq    #%1111,d0
  871.     Rbsr    L_EnvOff
  872.     Rbsr    L_RazWave
  873.     lea    Circuits,a0
  874.     move.w    #$000F,DmaCon(a0)
  875.     clr.w    $a8(a0)
  876.     clr.w    $b8(a0)
  877.     clr.w    $c8(a0)
  878.     clr.w    $d8(a0)
  879. * Finished!
  880.     rts
  881.  
  882. ******* LOOK FOR MUSIC BANK
  883. ; This routine is called after any bank has been loaded, reserved or erased.
  884. ; Here, if a music is being played and if the music bank is erased, I MUST
  885. ; stop the music, otherwise it might crash the computer. That's why I
  886. ; do a checksum on the first bytes of the bank to see if they have changed...
  887. BkCheck    
  888.     Rbsr    L_TrackCheck        * Check Tracker
  889.     Rbsr    L_MedCheck        * Check Med
  890. * Check normal music.
  891.     DLoad    a3
  892.     move.l    MusBank-MB(a3),d2    Old music bank address
  893.     moveq    #3,d0            Ask for music bank address
  894.     Rjsr    L_Bnk.GetAdr
  895.     beq.s    BkNo
  896.     move.l    -8(a0),d0        Looks for "Musi"
  897.     cmp.l    BkMus-MB(a3),d0
  898.     bne.s    BkNo
  899.     moveq    #0,d0            Performs a check sum
  900.     add.l    (a0),d0
  901.     add.l    4(a0),d0
  902.     add.l    8(a0),d0
  903.     add.l    12(a0),d0
  904.     cmp.l    d2,a0
  905.     bne.s    BkNew
  906.     cmp.l    MusCheck-MB(a3),d0
  907.     bne.s    BkNew
  908. * Same bank! Do nothing!
  909.     rts
  910. * No more bank!
  911. BkNo    tst.l    d2
  912.     beq.s    BkNo1
  913.     Rbsr    L_MuInit
  914.     clr.l    MusBank-MB(a3)
  915. BkNo1    rts
  916. * A NEW bank
  917. BkNew    move.l    a0,MusBank-MB(a3)
  918.     move.l    d0,MusCheck-MB(a3)
  919.     Rbsr    L_MuInit
  920.     move.l    MusBank-MB(a3),a0
  921.     move.l    a0,a1
  922.     add.l    (a0),a1
  923.     move.l    a1,BankInst-MB(a3)
  924.     move.l    a0,a1
  925.     add.l    4(a0),a1
  926.     move.l    a1,BankSong-MB(a3)
  927.     add.l    8(a0),a0
  928.     move.l    a0,BankPat-MB(a3)
  929.     rts
  930.  
  931. ***********************************************************
  932. *
  933. *    INTERRUPT ROUTINES
  934. *
  935. ***********************************************************    
  936.  
  937. ******* Sami interrupt handlers
  938. Sami_handler
  939.     add.w    Sami_reg(a1),a0
  940.     move.l    Sami_pos(a1),d0
  941.     cmp.l    Sami_long(a1),d0
  942.     bcc.s    .whatnow
  943. * Poursuit la lecture du sample
  944. .samloop
  945.     move.l    d0,d1
  946.     add.l    #Sami_lplay,d1
  947.     cmp.l    Sami_long(a1),d1
  948.     bls.s    .skip
  949.     move.l    Sami_long(a1),d1
  950. .skip    move.l    d1,Sami_pos(a1)
  951.     sub.l    d0,d1
  952.     lsr.l    #1,d1
  953.     add.l    Sami_adr(a1),d0
  954.     move.l    d0,(a0)                * AUDxLOC
  955.     move.w    d1,4(a0)            * AUDxLEN
  956.     move.w    Sami_dvol(a1),d0
  957.     bmi.s    .skip1
  958.     move.w    d0,8(a0)            * AUDxVOL
  959. .skip1    move.w    Sami_bit(a1),Circuits+IntReq
  960.     rts
  961. * Sample termine. Que faire?
  962. .whatnow
  963.     move.l    d0,d1
  964.     move.l    Sami_radr(a1),d0        * Double buffer?
  965.     bne.s    .swap
  966.     move.l    Sami_rpos(a1),d0        * Boucler?
  967.     bpl.s    .samloop
  968.     bset    #7,Sami_pos(a1)            * Attend?
  969.     tst.l    d1
  970.     bpl.s    .skip1
  971. * Fin du sample-> met du blanc!
  972.     move.w    #0,$a(a0)
  973.     move.w    Sami_dma(a1),d0
  974.     moveq    #0,d1
  975.     bset    d0,d1
  976.     move.w    d1,Circuits+DmaCon
  977.     tst.w    Sami_dvol(a1)
  978.     bmi.s    .skip2
  979.     lea    MB(pc),a0            * Restart music
  980.     bset    d0,MuReStart+1-MB(a0)
  981. .skip2    move.w    Sami_bit(a1),Circuits+IntEna    * No more interrupts
  982.     move.w    Sami_bit(a1),Circuits+IntReq
  983.     rts
  984. * Change de buffer
  985. .swap    clr.l    Sami_radr(a1)
  986.     move.l    d0,Sami_adr(a1)
  987.     move.l    Sami_rlong(a1),Sami_long(a1)
  988.     moveq    #0,d0
  989.     bra    .samloop
  990.  
  991. ******* VBL Entry
  992. MusInt    lea    MB(pc),a3    
  993.     move.w    EnvOn-MB(a3),d0
  994.     beq    Music
  995.     lea    EnvBase-MB(a3),a0
  996.     lea    $a0(a6),a2
  997.     moveq    #0,d1
  998.     moveq    #3,d2
  999.     moveq    #0,d5
  1000. MuInt1    btst    d1,d0
  1001.     beq.s    MuIntN
  1002.     move.l    EnvDelta(a0),d3
  1003.     add.l    EnvVol(a0),d3
  1004.     move.l    d3,EnvVol(a0)
  1005.     swap    d3
  1006.     move.w    d3,8(a2)
  1007. MuInt2    subq.w    #1,EnvNb(a0)
  1008.     bne.s    MuIntN
  1009.     Rbsr    L_MuIntE
  1010. MuIntN    lea    EnvLong(a0),a0
  1011.     lea    $10(a2),a2
  1012.     addq.w    #1,d1
  1013.     dbra    d2,MuInt1
  1014.     move.w    d0,EnvOn-MB(a3)
  1015.     move.w    d5,DmaCon(a6)
  1016.     lsl.w    #7,d5
  1017.     move.w    d5,IntEna(a6)
  1018. ******* Make noise?
  1019.     tst.w    Noise-MB(a3)
  1020.     beq.s    Music
  1021.     move.w    PNoise-MB(a3),d0
  1022.     moveq    #7,d2
  1023.     move.w    BSeed-MB(a3),d1
  1024.     move.l    WaveBase-MB(a3),a0
  1025. INoi1    add.w    6(a6),d1
  1026.     mulu    #$3171,d1
  1027.     lsr.l    #8,d1
  1028.     move.w    d1,WaveDeb(a0,d0.w)
  1029.     subq.w    #2,d0
  1030.     bpl.s    INoi2
  1031.     move.w    #LNoise-2,d0
  1032. INoi2    dbra    d2,INoi1
  1033.     move.w    d0,PNoise-MB(a3)
  1034.     move.w    d1,BSeed-MB(a3)
  1035.  
  1036. *******    Music routine
  1037. Music:    move.l    MuBase-MB(a3),d0
  1038.     beq    Tracker
  1039.     movem.l    a4-a6,-(sp)
  1040.     move.l    d0,a5
  1041.     bsr    MuEvery
  1042. * Here is a smart counter, which gives progressive results
  1043. * from zero to 100(PAL), 120(NTSC)...
  1044.     move.w    MuCpt(a5),d0
  1045.     add.w    MuTempo(a5),d0
  1046.     move.w    d0,MuCpt(a5)
  1047.     move.w    TempoBase-MB(a3),d1
  1048.     cmp.w    d1,d0
  1049.     bcs    MuEff
  1050.     sub.w    d1,MuCpt(a5)
  1051. * Lets go for one step of music!
  1052.     moveq    #0,d5
  1053.     moveq    #0,d7
  1054.     move.l    a5,a4
  1055.  
  1056.     tst.b    VoiCpt+1(a4)
  1057.     beq.s    Mus0
  1058.     addq.w    #1,d5
  1059.     subq.b    #1,VoiCpt+1(a4)
  1060.     bne.s    Mus0
  1061.     moveq    #0,d6
  1062.     move.l    MuChip0-MB(a3),a6
  1063.     bsr    MuStep
  1064. Mus0    
  1065.     lea    MuVoix1(a5),a4
  1066.     tst.b    VoiCpt+1(a4)
  1067.     beq.s    Mus1
  1068.     addq.w    #1,d5
  1069.     subq.b    #1,VoiCpt+1(a4)
  1070.     bne.s    Mus1
  1071.     moveq    #1,d6
  1072.     move.l    MuChip1-MB(a3),a6
  1073.     bsr    MuStep
  1074. Mus1
  1075.     lea    MuVoix2(a5),a4
  1076.     tst.b    VoiCpt+1(a4)
  1077.     beq.s    Mus2
  1078.     addq.w    #1,d5
  1079.     subq.b    #1,VoiCpt+1(a4)
  1080.     bne.s    Mus2
  1081.     moveq    #2,d6
  1082.     move.l    MuChip2-MB(a3),a6
  1083.     bsr    MuStep
  1084. Mus2    
  1085.     lea    MuVoix3(a5),a4
  1086.     tst.b    VoiCpt+1(a4)
  1087.     beq.s    Mus3
  1088.     addq.w    #1,d5
  1089.     subq.b    #1,VoiCpt+1(a4)
  1090.     bne.s    Mus3
  1091.     moveq    #3,d6
  1092.     move.l    MuChip3-MB(a3),a6
  1093.     bsr    MuStep
  1094. Mus3    
  1095.     and.w    MuDMAsk-MB(a3),d7
  1096.     move.w    d7,$DFF096
  1097.     tst.w    d5
  1098.     beq.s    MuFin
  1099.     bne.s    MuEnd
  1100. MuEff    bsr    DoEffects
  1101. MuEnd    movem.l    (sp)+,a4-a6
  1102. MuEnd1    rts
  1103. * Finished?
  1104. MuFin    subq.w    #1,MuNumber-MB(a3)
  1105.     beq    MuFini
  1106. * Restarts previous music
  1107.     move.w    MuNumber-MB(a3),d0
  1108.     subq.w    #1,d0
  1109.     mulu    #MuLong,d0
  1110.     lea    MuBuffer-MB(a3),a0
  1111.     add.w    d0,a0
  1112.     move.l    a0,MuBase-MB(a3)
  1113.     move.w    MuDMAsk-MB(a3),MuReStart-MB(a3)
  1114.     clr.w    MuStart(a0)
  1115.     clr.w    MuStop(a0)
  1116.     bra.s    MuEnd
  1117. * Really finished!
  1118. MuFini    clr.l    MuBase-MB(a3)
  1119.     Rbsr    L_MOff
  1120.     bra.s    MuEnd
  1121.  
  1122. ******* One step of music for one voice
  1123. MuStep    lea    MuJumps(pc),a1
  1124.     move.l    VoiAdr(a4),a2
  1125. MuSt0    move.w    (a2)+,d0
  1126.     bpl.s    DoNote
  1127.     move.w    d0,d1
  1128.     and.w    #$7F00,d0
  1129.     lsr.w    #6,d0
  1130.     jmp    0(a1,d0.w)
  1131.  
  1132. ******* Play a note
  1133. DoNote    btst    #14,d0
  1134.     bne.s    OldNote
  1135. * Play normal note
  1136.     and.w    #$0FFF,d0
  1137.     move.l    BankInst-MB(a3),d1
  1138.     move.l    VoiInst(a4),a0
  1139.     add.l    (a0),d1
  1140.     move.l    d1,(a6)
  1141.     move.w    8(a0),$04(a6)
  1142.     bset    d6,d7
  1143.     bclr    d6,MuStop+1(a5)
  1144.     bset    d6,MuStart+1(a5)
  1145.     move.b    VoiVol+1(a4),0(a3,d6.w)
  1146.     tst.b    VoiPTone(a4)
  1147.     bne.s    MuSt1
  1148. * No portamento
  1149.     move.w    d0,VoiNote(a4)
  1150.     move.w    d0,$06(a6)
  1151.     bra.s    MuSt0
  1152. * Start portamento
  1153. MuSt1    clr.b    VoiPTone(a4)
  1154.     move.w    d0,VoiPToTo(a4)
  1155.     lea    MuPTone(pc),a0
  1156.     move.l    a0,VoiEffect(a4)
  1157.     bra.s    MuSt0
  1158. * Play note compatible with first version
  1159. OldNote    move.w    d0,VoiCpt(a4)
  1160.     move.w    (a2)+,d0
  1161.     beq.s    ONoteE
  1162.     and.w    #$0FFF,d0
  1163.     move.w    d0,VoiNote(a4)
  1164.     move.w    d0,$06(a6)
  1165.     move.l    BankInst-MB(a3),d0
  1166.     move.l    VoiInst(a4),a0
  1167.     add.l    (a0),d0
  1168.     move.l    d0,(a6)
  1169.     move.w    8(a0),$04(a6)
  1170.     bset    d6,d7
  1171.     bclr    d6,MuStop+1(a5)
  1172.     bset    d6,MuStart+1(a5)
  1173.     move.b    VoiVol+1(a4),0(a3,d6.w)
  1174. ONoteE    move.l    a2,VoiAdr(a4)
  1175.     rts
  1176.  
  1177. ******* Jump table to labels
  1178. MuJumps    bra    EtEnd            * 00-> Fin pattern
  1179.     bra    MuSt0            * 01-> Old Slide up
  1180.     bra    MuSt0            * 02-> Old Slide down
  1181.     bra    EtSVol            * 03-> Set volume
  1182.     bra    EtStop            * 04-> Stop effet
  1183.     bra    EtRep            * 05-> Repeat
  1184.     bra    EtLOn            * 06-> Led On
  1185.     bra    EtLOff            * 07-> Led Off
  1186.     bra    EtTemp            * 08-> Set Tempo
  1187.     bra    EtInst            * 09-> Set Instrument
  1188.     bra    EtArp            * 10-> Arpeggiato
  1189.     bra    EtPort            * 11-> Portamento
  1190.     bra    EtVib            * 12-> Vibrato
  1191.     bra    EtVSl            * 13-> Volume slide
  1192.     bra    EtSlU            * 14-> Slide up
  1193.     bra    EtSlD            * 15-> Slide down
  1194.      bra    EtDel            * 16-> Delay
  1195.     bra    EtJmp            * 17-> Position jump
  1196.     bra    MuSt0            * 18-> Free space
  1197.     bra    MuSt0            * 19-> Free space
  1198.     bra    MuSt0            * 20-> Free space
  1199.     bra    MuSt0            * 21-> Free space
  1200.     bra    MuSt0            * 22-> Free space
  1201.     bra    MuSt0            * 23-> Free space
  1202.     bra    MuSt0            * 24-> Free space
  1203.     bra    MuSt0            * 25-> Free space
  1204.     bra    MuSt0            * 26-> Free space
  1205.     bra    MuSt0            * 27-> Free space
  1206.     bra    MuSt0            * 28-> Free space
  1207.     bra    MuSt0            * 29-> Free space
  1208.     bra    MuSt0            * 30-> Free space
  1209.     bra    MuSt0            * 31-> Free space
  1210.  
  1211. ******* End of a pattern
  1212. EtEnd    clr.w    VoiCpt(a4)
  1213.     clr.w    VoiRep(a4)
  1214.     clr.l    VoiDeb(a4)
  1215.     lea    NoEffect(pc),a0
  1216.     move.l    a0,VoiEffect(a4)
  1217.     move.l    VoiPat(a4),a0
  1218. RePat    moveq    #0,d0
  1219.     move.w    (a0)+,d0
  1220.     bmi.s    EtEnd1
  1221.     move.l    a0,VoiPat(a4)
  1222.     move.l    BankPat-MB(a3),a0
  1223.     cmp.w    (a0),d0
  1224.     bhi.s    EtEndX
  1225.     lsl.w    #2,d0
  1226.     add.w    d6,d0
  1227.     lsl.w    #1,d0
  1228.     move.w    2(a0,d0.w),d0
  1229.     beq.s    EtEndX
  1230.     lea    0(a0,d0.l),a2
  1231.     bra    MuSt0
  1232. EtEndX    rts
  1233. EtEnd1    cmp.w    #-1,d0
  1234.     beq.s    EtEndX
  1235.      move.l    VoiDPat(a4),a0
  1236.     bra.s    RePat
  1237. ******* Change instrument
  1238. EtInst    and.w    #$00FF,d1
  1239.     move.l    BankInst-MB(a3),a0
  1240.     lsl.w    #5,d1
  1241.     lea    2(a0,d1.w),a0
  1242.     move.l    a0,VoiInst(a4)
  1243.     move.w    12(a0),d0
  1244.     cmp.w    #64,d0
  1245.     bcs.s    EtInst1
  1246.     moveq    #63,d0
  1247. EtInst1    move.w    d0,VoiDVol(a4)
  1248.     mulu    MuVolume-MB(a3),d0
  1249.     lsr.w    #6,d0
  1250.     move.w    d0,VoiVol(a4)
  1251.     bra    MuSt0
  1252. ******* Set Volume
  1253. EtSVol    and.w    #$00FF,d1
  1254.     cmp.w    #64,d1
  1255.     bcs.s    EtSVol1
  1256.     moveq    #63,d1
  1257. EtSVol1    move.w    d1,VoiDVol(a4)
  1258.     mulu    MuVolume-MB(a3),d1
  1259.     lsr.w    #6,d1
  1260.     move.w    d1,VoiVol(a4)
  1261.     bra    MuSt0
  1262. ******* Set Tempo
  1263. EtTemp    and.w    #$00FF,d1
  1264.     move.w    d1,MuTempo(a5)
  1265.     bra    MuSt0
  1266. ******* Led On
  1267. EtLOn    bclr    #1,$bfe001
  1268.     bra    MuSt0
  1269. ******* Led Off
  1270. EtLOff    bset    #1,$bfe001
  1271.     bra    MuSt0
  1272. ******* Repeat
  1273. EtRep    and.w    #$00FF,d1
  1274.     bne.s    EtRep1
  1275.     move.l    a2,VoiDeb(a4)
  1276.     bra    MuSt0
  1277. EtRep1    tst.w    VoiRep(a4)
  1278.     bne.s    EtRep2
  1279.     move.w    d1,VoiRep(a4)
  1280.     bra    MuSt0
  1281. EtRep2    subq.w    #1,VoiRep(a4)
  1282.     beq    MuSt0
  1283.     move.l    VoiDeb(a4),d0
  1284.     beq    MuSt0
  1285.     move.l    d0,a2
  1286.     bra    MuSt0
  1287. ******* Arpeggio
  1288. EtArp    move.b    d1,VoiValue+1(a4)
  1289.     lea    MuArp(pc),a0
  1290.     move.l    a0,VoiEffect(a4)
  1291.     bra    MuSt0
  1292. ******* Portamento
  1293. EtPort    move.b    #1,VoiPTone(a4)
  1294.     lea    MuPTone(pc),a0
  1295.     bra.s    EtSetE
  1296. ******* Vibrato
  1297. EtVib    lea    MuVib(pc),a0
  1298.     bra.s    EtSetE
  1299. ******* Volume slide
  1300. EtVSl    and.w    #$00FF,d1
  1301.     move.w    d1,d0
  1302.     lsr.w    #4,d0
  1303.     tst.w    d0
  1304.     bne.s    VsEnd
  1305.     and.w    #$000F,d1
  1306.     neg.w    d1
  1307.     move.w    d1,d0
  1308. VsEnd    move.w    d0,VoiValue(a4)
  1309.     lea    MuVSl(pc),a0
  1310.     move.l    a0,VoiEffect(a4)
  1311.     bra    MuSt0
  1312. ******* Slide up
  1313. EtSlU    and.w    #$00FF,d1
  1314.     neg.w    d1
  1315.     lea    MuSlide(pc),a0
  1316.     bra.s    EtSte
  1317. ******* Slide Down
  1318. EtSlD    lea    MuSlide(pc),a0
  1319. EtSetE    and.w    #$00FF,d1
  1320. EtSte    move.w    d1,VoiValue(a4)
  1321.     move.l    a0,VoiEffect(a4)
  1322.     bra    MuSt0
  1323. ******* Stop effect
  1324. EtStop    lea    NoEffect(pc),a0
  1325.     move.l    a0,VoiEffect(a4)
  1326.     bra    MuSt0
  1327. ******* Jump to pattern
  1328. EtJmp    and.w    #$00FF,d1
  1329.     lsl.w    #1,d1
  1330.     move.l    VoiDPat(a4),a0
  1331.     add.w    d1,a0
  1332.     move.l    a0,VoiPat(a4)
  1333.     bra    EtEnd
  1334. ******* Delay
  1335. EtDel    move.w    d1,VoiCpt(a4)
  1336.     move.l    a2,VoiAdr(a4)
  1337.     rts
  1338.  
  1339. ******* Effect routines
  1340.  
  1341. * Performs all effects
  1342. DoEffects
  1343.     move.l    a5,a4
  1344.     move.l    MuChip0-MB(a3),a6
  1345.     move.l    VoiEffect(a4),a0
  1346.     jsr    (a0)
  1347.     move.w    VoiVol(a4),$08(a6)
  1348.     lea    MuVoix1(a5),a4
  1349.     move.l    MuChip1-MB(a3),a6
  1350.     move.l    VoiEffect(a4),a0
  1351.     jsr    (a0)
  1352.     move.w    VoiVol(a4),$08(a6)
  1353.     lea    MuVoix2(a5),a4
  1354.     move.l    MuChip2-MB(a3),a6
  1355.     move.l    VoiEffect(a4),a0
  1356.     jsr    (a0)
  1357.     move.w    VoiVol(a4),$08(a6)
  1358.     lea    MuVoix3(a5),a4
  1359.     move.l    MuChip3-MB(a3),a6
  1360.     move.l    VoiEffect(a4),a0
  1361.     jsr    (a0)
  1362.     move.w    VoiVol(a4),$08(a6)
  1363.     rts
  1364.  
  1365. * TONE SLIDE
  1366. MuSlide    move.w    VoiValue(a4),d0
  1367.     beq.s    NoMoreE
  1368.     add.w    VoiNote(a4),d0
  1369.     cmp.w    #$71,d0
  1370.     bcc.s    MuSl1
  1371.     moveq    #$71,d0
  1372.     bsr    NoMoreE
  1373. MuSl1    cmp.w    #$358,d0
  1374.     bls.s    MuSl2
  1375.     move.w    #$358,d0
  1376.     bsr    NoMoreE
  1377. MuSl2    move.w    d0,VoiNote(a4)
  1378.     move.w    d0,$06(a6)
  1379.     rts
  1380. NoMoreE    lea    NoEffect(pc),a0
  1381.     move.l    a0,VoiEffect(a4)
  1382.     rts
  1383. NoEffect
  1384.     move.w    VoiNote(a4),$06(a6)
  1385.     rts
  1386.  
  1387. * ARPEGGIO
  1388. MuArp    moveq    #0,d0
  1389.     move.b    VoiValue+1(a4),d0
  1390.     move.b    VoiValue(a4),d1
  1391.     cmp.b    #3,d1
  1392.     bcs.s    MuArp0
  1393.     moveq    #2,d1
  1394. MuArp0    subq.b    #1,d1
  1395.     move.b    d1,VoiValue(a4)
  1396.     beq.s    MuArp2
  1397.     bpl.s    MuArp1
  1398.     lsr.b    #4,d0
  1399.     bra.s    MuArp3
  1400. MuArp1    and.b    #$0f,d0
  1401.     bra.s    MuArp3
  1402. MuArp2    move.w    VoiNote(a4),d2
  1403.     bra.s    MuArp4
  1404. MuArp3    add.w    d0,d0
  1405.     moveq    #0,d1
  1406.     move.w    VoiNote(a4),d1
  1407.     lea    Periods(pc),a0
  1408.     moveq    #$24,d3
  1409. MuArpL    move.w    (a0,d0.w),d2
  1410.     cmp.w    (a0),d1
  1411.     bge.s    MuArp4
  1412.     addq.l    #2,a0
  1413.     dbra    d3,MuArpL
  1414.     rts
  1415. MuArp4    move.w    d2,$06(a6)
  1416.     rts
  1417.  
  1418. * PORTAMENTO
  1419. MuPTone    move.w    VoiValue(a4),d0
  1420.     move.w    VoiNote(a4),d1
  1421.     cmp.w    VoiPToTo(a4),d1
  1422.     beq.s    MuPTo3
  1423.     bcs.s    MuPTo1
  1424.     sub.w    d0,d1
  1425.     cmp.w    VoiPToTo(a4),d1
  1426.     bhi.s    MuPto4
  1427.     bra.s    MuPTo2
  1428. MuPTo1    add.w    d0,d1
  1429.     cmp.w    VoiPToTo(a4),d1
  1430.     bcs.s    MuPTo4
  1431. MuPTo2    move.w    VoiPToTo(a4),d1
  1432. MuPTo3    bsr    NoMoreE
  1433. MuPTo4    move.w    d1,VoiNote(a4)
  1434.     move.w    d1,$06(a6)
  1435.     rts
  1436.  
  1437. * VIBRATO
  1438. MuVib    move.b    VoiVib(a4),d0
  1439.     lea    Sinus(pc),a0
  1440.     lsr.w    #2,d0
  1441.     and.w    #$1f,d0
  1442.     moveq    #0,d2
  1443.     move.b    0(a0,d0.w),d2
  1444.     move.b    VoiValue+1(a4),d0
  1445.     and.w    #$0F,d0
  1446.     mulu    d0,d2
  1447.     lsr.w    #$06,d2
  1448.     move.w    VoiNote(a4),d0
  1449.     tst.b    VoiVib(a4)
  1450.     bmi.s    MuVib1
  1451.     add.w    d2,d0
  1452.     bra.s    MuVib2
  1453. MuVib1    sub.w    d2,d0
  1454. MuVib2    move.w    d0,$06(a6)
  1455.     move.b    VoiValue+1(a4),d0
  1456.     lsr.w    #2,d0
  1457.     and.w    #$3C,d0
  1458.     add.b    d0,VoiVib(a4)
  1459.     rts
  1460.  
  1461. * VOLUME SLIDE
  1462. MuVSl    move.w    VoiDVol(a4),d0
  1463.     add.w    VoiValue(a4),d0
  1464.     bpl.s    MuVSl1
  1465.     clr.w    d0
  1466. MuVSl1    cmp.w    #$40,d0
  1467.     bcs.s    MuVSl2
  1468.     moveq    #$3F,d0
  1469. MuVSl2    move.w    d0,VoiDVol(a4)
  1470.     mulu    MuVolume-MB(a3),d0
  1471.     lsr.w    #6,d0
  1472.     move.w    d0,VoiVol(a4)
  1473.     rts
  1474.  
  1475. *******    Routine called every VBL
  1476. MuEvery    
  1477.  
  1478. * Second step of sample?
  1479.     move.w    MuStop(a5),d0
  1480.     beq    MuEvX
  1481.     move.l    BankInst-MB(a3),d1
  1482.     btst    #0,d0                * Voix 0
  1483.     beq.s    MuEv0
  1484.     move.l    MuChip0-MB(a3),a6
  1485.     move.l    VoiInst0(a5),a0
  1486.     move.l    d1,d2
  1487.     add.l    4(a0),d2
  1488.     move.l    d2,(a6)
  1489.     move.w    10(a0),$04(a6)
  1490. MuEv0    btst    #1,d0                * Voix 1
  1491.     beq.s    MuEv1
  1492.     move.l    MuChip1-MB(a3),a6
  1493.     move.l    VoiInst1(a5),a0
  1494.     move.l    d1,d2
  1495.     add.l    4(a0),d2
  1496.     move.l    d2,(a6)
  1497.     move.w    10(a0),$04(a6)
  1498. MuEv1    btst    #2,d0                * Voix 2
  1499.     beq.s    MuEv2
  1500.     move.l    MuChip2-MB(a3),a6
  1501.     move.l    VoiInst2(a5),a0
  1502.     move.l    d1,d2
  1503.     add.l    4(a0),d2
  1504.     move.l    d2,(a6)
  1505.     move.w    10(a0),$04(a6)
  1506. MuEv2    btst    #3,d0                * Voix 3
  1507.     beq.s    MuEv3
  1508.     move.l    MuChip3-MB(a3),a6
  1509.     move.l    VoiInst3(a5),a0
  1510.     move.l    d1,d2
  1511.     add.l    4(a0),d2
  1512.     move.l    d2,(a6)
  1513.     move.w    10(a0),$04(a6)
  1514. MuEv3    
  1515.  
  1516. * Start a voice
  1517. MuEvX    move.w    MuStart(a5),d1
  1518.     move.w    d1,MuStop(a5)
  1519.     clr.w    MuStart(a5)
  1520.     or.w    d1,d0
  1521.     and.w    MuDMAsk-MB(a3),d0
  1522.     bset    #15,d0
  1523.     move.w    d0,$DFF096
  1524.  
  1525. * Restart voices?
  1526.     move.w    MuReStart-MB(a3),d0
  1527.     beq    MuRsX
  1528.     moveq    #0,d3
  1529.     btst    #0,d0                * Voix 0
  1530.     beq.s    MuRs0
  1531.     lea    $DFF0A0,a6
  1532.     move.l    a6,MuChip0-MB(a3)
  1533.     move.w    #2,$04(a6)
  1534.     tst.l    VoiInst0(a5)
  1535.     beq.s    MuRs0
  1536.     bset    #0,d3
  1537. MuRs0    btst    #1,d0                * Voix 1
  1538.     beq.s    MuRs1
  1539.     lea    $DFF0B0,a6
  1540.     move.l    a6,MuChip1-MB(a3)
  1541.     move.w    #2,$04(a6)
  1542.     tst.l    VoiInst1(a5)
  1543.     beq.s    MuRs1
  1544.     bset    #1,d3
  1545. MuRs1    btst    #2,d0                * Voix 2
  1546.     beq.s    MuRs2
  1547.     lea    $DFF0C0,a6
  1548.     move.l    a6,MuChip2-MB(a3)
  1549.     move.w    #2,$04(a6)
  1550.     tst.l    VoiInst2(a5)
  1551.     beq.s    MuRs2
  1552.     bset    #2,d3
  1553. MuRs2    btst    #3,d0                * Voix 3
  1554.     beq.s    MuRs3
  1555.     lea    $DFF0D0,a6
  1556.     move.l    a6,MuChip3-MB(a3)
  1557.     move.w    #2,$04(a6)
  1558.     tst.l    VoiInst3(a5)
  1559.     beq.s    MuRs3
  1560.     bset    #3,d3
  1561. MuRs3    clr.w    MuReStart-MB(a3)
  1562.     or.w    d0,MuDMAsk-MB(a3)
  1563.     or.w    d3,MuStop(a5)
  1564. MuRsX    
  1565.     rts
  1566.  
  1567.  
  1568. ***********************************************************
  1569. *
  1570. *    TRACKER INTERRUPT ROUTINES
  1571. *
  1572. ***********************************************************    
  1573. Tracker    move.b    mt_on(pc),d0
  1574.     beq.s    .Skip
  1575.     movem.l    a4-a6,-(sp)
  1576. ; Poke les deuxiemes parties des samples
  1577. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1578.     tst.w    mt_dmacon-MB(a3)
  1579.     beq.s    .SkipD
  1580.     lea    mt_voice1(pc),a1
  1581.     lea    $dff000,a0
  1582.     move.l    $a(a1),$a0(a0)
  1583.     move.w    $e(a1),$a4(a0)
  1584.     move.l    $a+$1c(a1),$b0(a0)
  1585.     move.w    $e+$1c(a1),$b4(a0)
  1586.     move.l    $a+$38(a1),$c0(a0)
  1587.     move.w    $e+$38(a1),$c4(a0)
  1588.     move.l    $a+$54(a1),$d0(a0)
  1589.     move.w    $e+$54(a1),$d4(a0)
  1590. ; Appelle la musique
  1591. ; ~~~~~~~~~~~~~~~~~~
  1592. .SkipD    bsr    mt_music
  1593.     movem.l    (sp)+,a4-a6
  1594. .Skip    rts
  1595.  
  1596. mt_music:
  1597.     move.l    mt_data(pc),a0
  1598.     lea    mt_voice1(pc),a4
  1599.     addq.b    #1,mt_counter-mt_voice1(a4)
  1600.     move.b    mt_counter(pc),d0
  1601.     cmp.b    mt_speed(pc),d0
  1602.     blt    mt_nonew
  1603.     moveq    #0,d0
  1604.     move.b    d0,mt_counter-mt_voice1(a4)
  1605.     move.w    d0,mt_dmacon-mt_voice1(a4)
  1606.     move.l    mt_data(pc),a0
  1607.     lea    $3b8(a0),a2
  1608.     lea    $43c(a0),a0
  1609.  
  1610.     moveq    #0,d1
  1611.     move.b    mt_songpos(pc),d0
  1612.     move.b    (a2,d0.w),d1
  1613.     lsl.w    #8,d1
  1614.     lsl.w    #2,d1
  1615.     add.w    mt_pattpos(pc),d1
  1616.  
  1617.     lea    $dff0a0,a5
  1618.     lea    mt_samplestarts-4(pc),a1
  1619.     lea    mt_playvoice(pc),a6
  1620.     jsr    (a6)
  1621.     addq.l    #4,d1
  1622.     lea    $dff0b0,a5
  1623.     lea    mt_voice2(pc),a4
  1624.     jsr    (a6)
  1625.     addq.l    #4,d1
  1626.     lea    $dff0c0,a5
  1627.     lea    mt_voice3(pc),a4
  1628.     jsr    (a6)
  1629.     addq.l    #4,d1
  1630.     lea    $dff0d0,a5
  1631.     lea    mt_voice4(pc),a4
  1632.     jsr    (a6)
  1633.  
  1634.     move.w    mt_dmacon(pc),d0
  1635.     beq.s    mt_nodma
  1636.     or.w    #$8000,mt_dmacon-mt_voice4(a4)
  1637.  
  1638. mt_nodma:
  1639.     add.w    #$10,mt_pattpos-mt_voice4(a4)
  1640.     cmp.w    #$400,mt_pattpos-mt_voice4(a4)
  1641.     bne.s    mt_exit
  1642. mt_next:clr.w    mt_pattpos-mt_voice4(a4)
  1643.     clr.b    mt_break-mt_voice4(a4)
  1644.     addq.b    #1,mt_songpos-mt_voice4(a4)
  1645.     and.b    #$7f,mt_songpos-mt_voice4(a4)
  1646.     move.b    -2(a2),d0
  1647.     cmp.b    mt_songpos(pc),d0
  1648.     bne.s    mt_exit
  1649.     move.b    -1(a2),mt_songpos-mt_voice4(a4)
  1650. mt_exit:tst.b    mt_break-mt_voice4(a4)
  1651.     bne.s    mt_next
  1652. ; Provoque l'actualisation du DMA
  1653.     move.w    mt_dmacon(pc),d0
  1654.     beq.s    .Skip
  1655.     moveq    #4,d3        
  1656. .wai2    move.b    $dff006,d2    
  1657. .wai3    cmp.b    $dff006,d2    
  1658.     beq.s    .wai3
  1659.     dbf    d3,.wai2    
  1660.     move.w    d0,$dff096
  1661. .Skip    rts
  1662.  
  1663. mt_nonew:
  1664.     lea    $dff0a0,a5
  1665.     lea    mt_com(pc),a6
  1666.     jsr    (a6)
  1667.     lea    mt_voice2(pc),a4
  1668.     lea    $dff0b0,a5
  1669.     jsr    (a6)
  1670.     lea    mt_voice3(pc),a4
  1671.     lea    $dff0c0,a5
  1672.     jsr    (a6)
  1673.     lea    mt_voice4(pc),a4
  1674.     lea    $dff0d0,a5
  1675.     jsr    (a6)
  1676.     tst.b    mt_break-mt_voice4(a4)
  1677.     bne    mt_next
  1678.     rts
  1679.  
  1680. mt_playvoice:
  1681.     move.l    (a0,d1.l),(a4)
  1682.     moveq    #0,d2
  1683.     move.b    2(a4),d2
  1684.     lsr.b    #4,d2
  1685.     move.b    (a4),d0
  1686.     and.b    #$f0,d0
  1687.     or.b    d0,d2
  1688.     beq    mt_oldinstr
  1689.  
  1690.     asl.w    #2,d2
  1691.     move.l    (a1,d2.l),4(a4)
  1692.     move.l    mt_mulu(pc,d2.w),a3
  1693.     move.w    (a3)+,8(a4)
  1694.     move.w    (a3)+,$12(a4)
  1695.     move.l    4(a4),d0
  1696.     moveq    #0,d3
  1697.     move.w    (a3)+,d3
  1698.     beq    mt_noloop
  1699.     asl.w    #1,d3
  1700.     add.l    d3,d0
  1701.     move.l    d0,$a(a4)
  1702.     move.w    -2(a3),d0
  1703.     add.w    (a3),d0
  1704.     move.w    d0,8(a4)
  1705.     bra    mt_hejaSverige
  1706.  
  1707. mt_mulu:dcb.l    $20,0
  1708.  
  1709. mt_noloop:
  1710.     add.l    d3,d0
  1711.     move.l    d0,$a(a4)
  1712. mt_hejaSverige:
  1713.     move.w    (a3),$e(a4)
  1714.     move.w    $12(a4),8(a5)
  1715.  
  1716. mt_oldinstr:
  1717.     move.w    (a4),d3
  1718.     and.w    #$fff,d3
  1719.     beq    mt_com2
  1720.     tst.w    8(a4)
  1721.     beq.s    mt_stopsound
  1722.     move.b    2(a4),d0
  1723.     and.b    #$f,d0
  1724.     cmp.b    #5,d0
  1725.     beq.s    mt_setport
  1726.     cmp.b    #3,d0
  1727.     beq.s    mt_setport
  1728.  
  1729.     move.w    d3,$10(a4)
  1730.     move.w    $1a(a4),$dff096
  1731.     clr.b    $19(a4)
  1732.  
  1733.     move.l    4(a4),(a5)
  1734.     move.w    8(a4),4(a5)
  1735.     move.w    $10(a4),6(a5)
  1736.  
  1737.     move.w    $1a(a4),d0
  1738.     or.w    d0,mt_dmacon-mt_playvoice(a6)
  1739.     bra    mt_com2
  1740.  
  1741. mt_stopsound:
  1742.     move.w    $1a(a4),$dff096
  1743.     bra    mt_com2
  1744.  
  1745. mt_setport:
  1746.     move.w    (a4),d2
  1747.     and.w    #$fff,d2
  1748.     move.w    d2,$16(a4)
  1749.     move.w    $10(a4),d0
  1750.     clr.b    $14(a4)
  1751.     cmp.w    d0,d2
  1752.     beq.s    mt_clrport
  1753.     bge    mt_com2
  1754.     move.b    #1,$14(a4)
  1755.     bra    mt_com2
  1756. mt_clrport:
  1757.     clr.w    $16(a4)
  1758.     rts
  1759.  
  1760. mt_port:moveq    #0,d0
  1761.     move.b    3(a4),d2
  1762.     beq.s    mt_port2
  1763.     move.b    d2,$15(a4)
  1764.     move.b    d0,3(a4)
  1765. mt_port2:
  1766.     tst.w    $16(a4)
  1767.     beq.s    mt_rts
  1768.     move.b    $15(a4),d0
  1769.     tst.b    $14(a4)
  1770.     bne.s    mt_sub
  1771.     add.w    d0,$10(a4)
  1772.     move.w    $16(a4),d0
  1773.     cmp.w    $10(a4),d0
  1774.     bgt.s    mt_portok
  1775.     move.w    $16(a4),$10(a4)
  1776.     clr.w    $16(a4)
  1777. mt_portok:
  1778.     move.w    $10(a4),6(a5)
  1779. mt_rts:    rts
  1780.  
  1781. mt_sub:    sub.w    d0,$10(a4)
  1782.     move.w    $16(a4),d0
  1783.     cmp.w    $10(a4),d0
  1784.     blt.s    mt_portok
  1785.     move.w    $16(a4),$10(a4)
  1786.     clr.w    $16(a4)
  1787.     move.w    $10(a4),6(a5)
  1788.     rts
  1789.  
  1790. mt_sin:
  1791.     dc.b $00,$18,$31,$4a,$61,$78,$8d,$a1,$b4,$c5,$d4,$e0,$eb,$f4,$fa,$fd
  1792.     dc.b $ff,$fd,$fa,$f4,$eb,$e0,$d4,$c5,$b4,$a1,$8d,$78,$61,$4a,$31,$18
  1793.  
  1794. mt_vib:    move.b    $3(a4),d0
  1795.     beq.s    mt_vib2
  1796.     move.b    d0,$18(a4)
  1797.  
  1798. mt_vib2:move.b    $19(a4),d0
  1799.     lsr.w    #2,d0
  1800.     and.w    #$1f,d0
  1801.     moveq    #0,d2
  1802.     move.b    mt_sin(pc,d0.w),d2
  1803.     move.b    $18(a4),d0
  1804.     and.w    #$f,d0
  1805.     mulu    d0,d2
  1806.     lsr.w    #7,d2
  1807.     move.w    $10(a4),d0
  1808.     tst.b    $19(a4)
  1809.     bmi.s    mt_vibsub
  1810.     add.w    d2,d0
  1811.     bra.s    mt_vib3
  1812. mt_vibsub:
  1813.     sub.w    d2,d0
  1814. mt_vib3:move.w    d0,6(a5)
  1815.     move.b    $18(a4),d0
  1816.     lsr.w    #2,d0
  1817.     and.w    #$3c,d0
  1818.     add.b    d0,$19(a4)
  1819.     rts
  1820.  
  1821. mt_arplist:
  1822.     dc.b 0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1
  1823.  
  1824. mt_arp:    moveq    #0,d0
  1825.     move.b    mt_counter(pc),d0
  1826.     move.b    mt_arplist(pc,d0.w),d0
  1827.     beq.s    mt_normper
  1828.     cmp.b    #2,d0
  1829.     beq.s    mt_arp2
  1830. mt_arp1:move.b    3(a4),d0
  1831.     lsr.w    #4,d0
  1832.     bra.s    mt_arpdo
  1833. mt_arp2:move.b    3(a4),d0
  1834.     and.w    #$f,d0
  1835. mt_arpdo:
  1836.     asl.w    #1,d0
  1837.     move.w    $10(a4),d1
  1838.     lea    mt_periods(pc),a0
  1839. mt_arp3:cmp.w    (a0)+,d1
  1840.     blt.s    mt_arp3
  1841.     move.w    -2(a0,d0.w),6(a5)
  1842.     rts
  1843.  
  1844. mt_normper:
  1845.     move.w    $10(a4),6(a5)
  1846.     rts
  1847.  
  1848. mt_com:    move.w    2(a4),d0
  1849.     and.w    #$fff,d0
  1850.     beq.s    mt_normper
  1851.     move.b    2(a4),d0
  1852.     and.b    #$f,d0
  1853.     beq.s    mt_arp
  1854.     cmp.b    #6,d0
  1855.     beq.s    mt_volvib
  1856.     cmp.b    #4,d0
  1857.     beq    mt_vib
  1858.     cmp.b    #5,d0
  1859.     beq.s    mt_volport
  1860.     cmp.b    #3,d0
  1861.     beq    mt_port
  1862.     cmp.b    #1,d0
  1863.     beq.s    mt_portup
  1864.     cmp.b    #2,d0
  1865.     beq.s    mt_portdown
  1866.     move.w    $10(a4),6(a5)
  1867.     cmp.b    #$a,d0
  1868.     beq.s    mt_volslide
  1869.     rts
  1870.  
  1871. mt_portup:
  1872.     moveq    #0,d0
  1873.     move.b    3(a4),d0
  1874.     sub.w    d0,$10(a4)
  1875.     move.w    $10(a4),d0
  1876.     cmp.w    #$71,d0
  1877.     bpl.s    mt_portup2
  1878.     move.w    #$71,$10(a4)
  1879. mt_portup2:
  1880.     move.w    $10(a4),6(a5)
  1881.     rts
  1882.  
  1883. mt_portdown:
  1884.     moveq    #0,d0
  1885.     move.b    3(a4),d0
  1886.     add.w    d0,$10(a4)
  1887.     move.w    $10(a4),d0
  1888.     cmp.w    #$358,d0
  1889.     bmi.s    mt_portdown2
  1890.     move.w    #$358,$10(a4)
  1891. mt_portdown2:
  1892.     move.w    $10(a4),6(a5)
  1893.     rts
  1894.  
  1895. mt_volvib:
  1896.      bsr    mt_vib2
  1897.      bra.s    mt_volslide
  1898. mt_volport:
  1899.      bsr    mt_port2
  1900.  
  1901. mt_volslide:
  1902.     moveq    #0,d0
  1903.     move.b    3(a4),d0
  1904.     lsr.b    #4,d0
  1905.     beq.s    mt_vol3
  1906.     add.b    d0,$13(a4)
  1907.     cmp.b    #$40,$13(a4)
  1908.     bmi.s    mt_vol2
  1909.     move.b    #$40,$13(a4)
  1910. mt_vol2:move.w    $12(a4),8(a5)
  1911.     rts
  1912.  
  1913. mt_vol3:move.b    3(a4),d0
  1914.     and.b    #$f,d0
  1915.     sub.b    d0,$13(a4)
  1916.     bpl.s    mt_vol4
  1917.     clr.b    $13(a4)
  1918. mt_vol4:move.w    $12(a4),8(a5)
  1919.     rts
  1920.  
  1921. mt_com2:move.b    2(a4),d0
  1922.     and.b    #$f,d0
  1923.     beq    mt_rts
  1924.     cmp.b    #$e,d0
  1925.     beq.s    mt_filter
  1926.     cmp.b    #$d,d0
  1927.     beq.s    mt_pattbreak
  1928.     cmp.b    #$b,d0
  1929.     beq.s    mt_songjmp
  1930.     cmp.b    #$c,d0
  1931.     beq.s    mt_setvol
  1932.     cmp.b    #$f,d0
  1933.     beq.s    mt_setspeed
  1934.     rts
  1935.  
  1936. mt_filter:
  1937.     move.b    3(a4),d0
  1938.     and.b    #1,d0
  1939.     asl.b    #1,d0
  1940.     and.b    #$fd,$bfe001
  1941.     or.b    d0,$bfe001
  1942.     rts
  1943.  
  1944. mt_pattbreak:
  1945.     move.b    #1,mt_break-mt_playvoice(a6)
  1946.     rts
  1947.  
  1948. mt_songjmp:
  1949.     move.b    #1,mt_break-mt_playvoice(a6)
  1950.     move.b    3(a4),d0
  1951.     subq.b    #1,d0
  1952.     move.b    d0,mt_songpos-mt_playvoice(a6)
  1953.     rts
  1954.  
  1955. mt_setvol:
  1956.     cmp.b    #$40,3(a4)
  1957.     bls.s    mt_sv2
  1958.     move.b    #$40,3(a4)
  1959. mt_sv2:    moveq    #0,d0
  1960.     move.b    3(a4),d0
  1961.     move.b    d0,$13(a4)
  1962.     move.w    d0,8(a5)
  1963.     rts
  1964.  
  1965. mt_setspeed:
  1966.     moveq    #0,d0
  1967.     move.b    3(a4),d0
  1968.     cmp.b    #$1f,d0
  1969.     bls.s    mt_sp2
  1970.     moveq    #$1f,d0
  1971. mt_sp2:    tst.w    d0
  1972.     bne.s    mt_sp3
  1973.     moveq    #1,d0
  1974. mt_sp3:    move.b    d0,mt_speed-mt_playvoice(a6)
  1975.     rts
  1976.  
  1977.  
  1978. *********************************************************************
  1979. *        MUSIC extension data zone
  1980.  
  1981. ; Branches for AMOSPro Editor (-4)
  1982. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1983.         Rbra    L_GoSam
  1984. MB:
  1985. MuVu        dc.l    0        * Vu Meters
  1986. MuBase        dc.l    0        * Curretn music address
  1987. MusAdr        dc.l    0        * Branch table address
  1988. MusClock    dc.l     3546895        * Clock speed
  1989. WaveBase    dc.l    0        * Wave tree
  1990. Waves        dc.w     0,0,0,0
  1991. EnvOn:        dc.w     0        * ADSR running?
  1992. EnvBase:    ds.b    EnvLong*4    * ADSR table
  1993. SamBank:    dc.w     0        * Sample bank
  1994. BSeed:        dc.w     0        * Random seed
  1995. Noise:        dc.w    0        * Noise on?
  1996. PNoise:        dc.w    0        * Pointer to noise buffer
  1997. TempoBase:    dc.w    0        * 100 (PAL) - 120 (NTSC)
  1998. *         Musique
  1999. MusBank        dc.l     0        * Music bank
  2000. MusCheck    dc.l    0        * Check sum
  2001. BankInst    dc.l    0        * Instruments
  2002. BankSong    dc.l    0        * Songs
  2003. BankPat        dc.l     0        * Patterns
  2004. MuNumber    dc.w    0        * Music priority
  2005. MuVolume    dc.w    0        * Music volume
  2006. MuDMAsk        dc.w    0        * Voice mask
  2007. MuReStart    dc.w    0        * Restart the voice
  2008. MuChip0        dc.l    0        * Circuits 0
  2009. MuChip1        dc.l     0        *       1
  2010. MuChip2        dc.l     0        *          2
  2011. MuChip3        dc.l     0        *          3
  2012. FoEnd        dc.w    $8000        * Fake empty pattern
  2013. MuBuffer    ds.b    MuLong*3    * Music tables
  2014.  
  2015.         RDATA
  2016.  
  2017. *************** Tables for effects
  2018. Sinus    
  2019.  dc.b $00,$18,$31,$4a,$61,$78,$8d,$a1,$b4,$c5,$d4,$e0,$eb,$f4,$fa,$fd
  2020.  dc.b $ff,$fd,$fa,$f4,$eb,$e0,$d4,$c5,$b4,$a1,$8d,$78,$61,$4a,$31,$18
  2021.  
  2022. Periods    
  2023.  dc.w $0358,$0328,$02fa,$02d0,$02a6,$0280,$025c,$023a,$021a,$01fc,$01e0
  2024.  dc.w $01c5,$01ac,$0194,$017d,$0168,$0153,$0140,$012e,$011d,$010d,$00fe
  2025.  dc.w $00f0,$00e2,$00d6,$00ca,$00be,$00b4,$00aa,$00a0,$0097,$008f,$0087
  2026.  dc.w $007f,$0078,$0071,$0000,$0000
  2027.  
  2028. *************** Default enveloppes
  2029. EnvDef:        dc.w 1,64,4,55,5,50,25,0,0,0
  2030. EnvShoot    dc.w 1,64,10,0,0,0
  2031. EnvBoom        dc.w 1,64,10,50,50,0,0,0
  2032. EnvBell        dc.w 1,64,4,40,25,0,0,0
  2033.  
  2034. *************** Bank headers
  2035. BkMus:        dc.b "Music   "
  2036.  
  2037. *************** Frequency / notes
  2038. TFreq:    dc.w 000,256/2
  2039.     dc.w 000,256/2
  2040.     dc.w 256,128/2
  2041.     dc.w 384,64/2
  2042.     dc.w 448,32/2
  2043.     dc.w 480,16/2
  2044.     dc.w 496,8/2
  2045.     dc.w 504,4/2
  2046.     dc.w 504,4/2
  2047. TNotes:    dc.w 00,00,00,33,35,37,39,41,44,46,49,52
  2048.     dc.w 55,58,62,65,69,73,78,82,87,92,98,104
  2049.     dc.w 110,117,123,131,139,147,156,165,175,185,196,208
  2050.     dc.w 220,233,247,262,277,294,311,330,349,370,392,415
  2051.     dc.w 440,466,494,523,554,587,622,659,698,740,784,830
  2052.     dc.w 880,932,988,1046,1109,1175,1245,1319,1397,1480,1568,1661
  2053.     dc.w 1760,1865,1986,2093,2217,2349,2489,2637,2794,2960,3136,3322
  2054.     dc.w 3520,3729,3952,4186,4435,4699,4978,5274,5588,5920,6272,6645
  2055.     dc.w 7040,7459,7902,8372
  2056.  
  2057. *************** SAMPLE PLAYER INTERRUPT STRUCTURES
  2058. Sami_lplay    equ    1024*4
  2059. Sami_bit    equ    22
  2060. Sami_dma    equ    24
  2061. Sami_reg    equ    26
  2062. Sami_adr    equ    28
  2063. Sami_long    equ    32
  2064. Sami_pos    equ    36
  2065. Sami_rpos    equ    40
  2066. Sami_radr    equ    44
  2067. Sami_rlong    equ    48
  2068. Sami_dvol    equ    52
  2069. Sami_old    equ    54
  2070. Sami_intl    equ    58
  2071.  
  2072. Sami_int    ds.b    22                * Channel 0
  2073.         dc.w    %0000000010000000    bit
  2074.         dc.w    0            dma
  2075.         dc.w    $a0            reg
  2076.         dc.l    0            adr
  2077.         dc.l    0            long
  2078.         dc.l    0            pos
  2079.         dc.l    0            rpos
  2080.         dc.l    0            radr
  2081.         dc.l    0            rlong
  2082.         dc.w    0            dvol
  2083.         dc.l    0            old            
  2084.  
  2085.         ds.b    22                * Channel 1
  2086.         dc.w    %0000000100000000    bit
  2087.         dc.w    1            dma
  2088.         dc.w    $b0            reg
  2089.         dc.l    0            adr
  2090.         dc.l    0            long
  2091.         dc.l    0            pos
  2092.         dc.l    0            rpos
  2093.         dc.l    0            radr
  2094.         dc.l    0            rlong
  2095.         dc.w    0            dvol
  2096.         dc.l    0            old            
  2097.  
  2098.         ds.b    22                * Channel 2
  2099.         dc.w    %0000001000000000    bit
  2100.         dc.w    2            dma
  2101.         dc.w    $c0            reg
  2102.         dc.l    0            adr
  2103.         dc.l    0            long
  2104.         dc.l    0            pos
  2105.         dc.l    0            rpos
  2106.         dc.l    0            radr
  2107.         dc.l    0            rlong
  2108.         dc.w    0            dvol
  2109.         dc.l    0            old            
  2110.  
  2111.         ds.b    22                * Channel 3
  2112.         dc.w    %0000010000000000    bit
  2113.         dc.w    3            dma
  2114.         dc.w    $d0            reg
  2115.         dc.l    0            adr
  2116.         dc.l    0            long
  2117.         dc.l    0            pos
  2118.         dc.l    0            rpos
  2119.         dc.l    0            radr
  2120.         dc.l    0            rlong
  2121.         dc.w    0            dvol
  2122.         dc.l    0            old            
  2123.  
  2124. Sami_OldEna    dc.w    0
  2125. Sami_empty    dc.l    0
  2126. Sami_bits    dc.w    0
  2127. Sami_handad    dc.l    0
  2128. Sami_flag    dc.w    0
  2129. SamLoops    dc.w    0
  2130. *************** NARRATOR
  2131. Amaps:        dc.b    3,5,10,12
  2132. TranBase    dc.l    0
  2133.         even
  2134. L_WriteIo    equ    88
  2135. WriteIo        dc.l    0
  2136. WritePort:    dc.l    0
  2137. L_ReadIo    equ    92
  2138. ReadIo        ds.b    L_ReadIo
  2139. ReadPort    dc.l    0
  2140. TranName    dc.b    "translator.library",0
  2141. NarDevice    dc.b    "narrator.device",0
  2142.         even
  2143.  
  2144. ;     MED data zone
  2145. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2146. Med_Bank    dc.w    7        Bank number 6= tracker
  2147. Med_Base    dc.l    0
  2148. Med_Adr        dc.l    0
  2149. Med_On        dc.b    0
  2150. Med_Midi    dc.b    0
  2151. Med_Name    dc.b    "medplayer.library",0    
  2152.         even
  2153. _MEDGetPlayer        equ    -30
  2154. _MEDFreePlayer        equ    -36
  2155. _MEDPlayModule        equ    -42
  2156. _MEDContModule        equ    -48
  2157. _MEDStopPlayer        equ    -54
  2158. _MEDDimOffPlayer    equ    -60
  2159. _MEDSetTempo        equ    -66
  2160. _MEDLoadModule        equ    -72
  2161. _MEDUnLoadModule    equ    -78
  2162. _MEDGetCurrentModule    equ    -84
  2163. _MEDResetMIDI        equ    -90
  2164. _MEDSetModnum        equ    -96
  2165. _MEDRelocModule        equ    -102
  2166.  
  2167. *********************************************************************
  2168. *    mt TRACKER data zone
  2169.  
  2170. Track_Bank    dc.w    6        Bank number 6= tracker
  2171. mt_on        dc.b    0
  2172. colour        dc.w    0
  2173.  
  2174. mt_periods:
  2175.     dc.w $0358,$0328,$02fa,$02d0,$02a6,$0280,$025c,$023a,$021a,$01fc,$01e0
  2176.     dc.w $01c5,$01ac,$0194,$017d,$0168,$0153,$0140,$012e,$011d,$010d,$00fe
  2177.     dc.w $00f0,$00e2,$00d6,$00ca,$00be,$00b4,$00aa,$00a0,$0097,$008f,$0087
  2178.     dc.w $007f,$0078,$0071,$0000
  2179.  
  2180. mt_speed:    dc.b    6
  2181. mt_counter:    dc.b    0
  2182. mt_pattpos:    dc.w    0
  2183. mt_songpos:    dc.b    0
  2184. mt_break:    dc.b    0
  2185. mt_dmacon:    dc.w    0
  2186. mt_samplestarts:dcb.l    $1f,0
  2187. mt_voice1:    dcb.w    13,0
  2188.         dc.w    1
  2189. mt_voice2:    dcb.w    13,0
  2190.         dc.w    2
  2191. mt_voice3:    dcb.w    13,0
  2192.         dc.w    4
  2193. mt_voice4:    dcb.w    13,0
  2194.         dc.w    8
  2195. mt_data:    dc.l    0
  2196.         dc.l    0
  2197.  
  2198.  
  2199. **********************************************************************
  2200. ; Please leave 1 or two labels free for future extension. You never
  2201. ; know!
  2202. L1
  2203.  
  2204. ; Now follow all the music routines. Some are just routines called by others,
  2205. ; some are instructions. 
  2206. ; See how a adress the internal music datazone, by using a base register
  2207. ; (usually A3) and adding the offset of the data in the datazone...
  2208.  
  2209. ; >>> How to get the parameters for the instruction?
  2210. ;
  2211. ; When an instruction or function is called, you get the parameters
  2212. ; pushed in A3. Remember that you unpile them in REVERSE order than
  2213. ; the instruction syntax.
  2214. ; As you have a entry point for each set of parameters, you know
  2215. ; how many are pushed...
  2216. ;    - INTEGER:    move.l    (a3)+,d0
  2217. ;    - STRING:    move.l    (a3)+,a0
  2218. ;            move.w    (a0)+,d0
  2219. ;        A0---> start of the string.
  2220. ;        D0---> length of the string
  2221. ;    - FLOAT:    move.l    (a3)+,d0
  2222. ;            fast floatting point format.
  2223. ;
  2224. ; IMPORTANT POINT: you MUST unpile the EXACT number of parameters,
  2225. ; to restore A3 to its original level. If you do not, you will not
  2226. ; have a immediate error, and AMOS will certainely crash on next
  2227. ; UNTIL / WEND / ENDIF / NEXT etc... 
  2228. ;
  2229. ; So, your instruction must:
  2230. ;    - Unpile the EXACT number of parameters from A3, and exit with
  2231. ;    A3 at the original level it was before collecting your parameters)
  2232. ;    - Preserve A4, A5 and A6
  2233. ; You can use D0-D7/A0-A2 freely...
  2234. ;
  2235. ; You can jump to the error routine without thinking about A3 if an error
  2236. ; occurs in your routine (via a RBra of course). BUT A4, A5 and A6 registers
  2237. ; MUST be preserved!
  2238. ;
  2239. ; You end must end by a RTS.
  2240. ;
  2241. ; >>> Functions, how to return the parameter?
  2242. ;
  2243. ; To send a function`s parameter back to AMOS, you load it in D3,
  2244. ; and put its type in D2:
  2245. ;    moveq    #0,d2    for an integer
  2246. ;    moveq    #1,d2    for a float
  2247. ;    moveq    #2,d2    for a string
  2248. ;
  2249.  
  2250. ******* Stop sound routine
  2251. L_MOff        equ    2
  2252. L2    lea    Circuits,a0
  2253.     move.w    #%0000011110000000,IntEna(a0)     * No more interrupts
  2254.     move.w    MuDMAsk-MB(a3),d0
  2255.     beq.s    MOf3
  2256.     move.w    d0,DmaCon(a0)
  2257.     moveq    #3,d1
  2258. MOf1    btst    d1,d0
  2259.     beq.s    MOf2
  2260.     move.w    #2,$a4(a0)
  2261.     clr.w    $a8(a0)
  2262. MOf2    lea    $10(a0),a0
  2263.     dbra    d1,MOf1
  2264. MOf3    rts
  2265.  
  2266. ***********************************************************
  2267. *    NARRATOR!
  2268.  
  2269. ******* Open narrator
  2270. L_OpNar        equ    3
  2271. L3    movem.l    a3-a6,-(sp)
  2272.     Dload    a3
  2273.     move.l    $4.w,a6
  2274.     move.l    TranBase-MB(a3),d0
  2275.     bne    OpNarCheck
  2276.  
  2277. ; Opens communication port
  2278.     clr.l    -(sp)
  2279.     clr.l    -(sp)
  2280.     moveq    #0,d0
  2281.     Rbsr    L_Amiga.Lib
  2282.     addq.l    #8,sp
  2283.     move.l    d0,WritePort-MB(a3)
  2284. ; Opens IO structure
  2285.     move.l    #L_WriteIo,-(sp)
  2286.     move.l    d0,-(sp)
  2287.     moveq    #2,d0
  2288.     Rbsr    L_Amiga.Lib
  2289.     addq.l    #8,sp
  2290.     move.l    d0,WriteIo-Mb(a3)
  2291.     move.l    d0,a1
  2292.     moveq    #0,d0
  2293.     moveq    #0,d1
  2294.     lea    NarDevice-MB(a3),a0
  2295.     jsr    OpenDev(a6)
  2296.     tst.l    d0
  2297.     bne    OpNarE
  2298.  
  2299. ; Open READ structure
  2300.     clr.l    -(sp)
  2301.     clr.l    -(sp)
  2302.     moveq    #0,d0
  2303.     Rbsr    L_Amiga.Lib
  2304.     addq.l    #8,sp
  2305.     move.l    d0,ReadPort-MB(a3)
  2306.     move.l    WriteIo-MB(a3),a0
  2307.     lea    ReadIo-MB(a3),a1
  2308.     moveq    #L_WriteIo/2-1,d0
  2309. .Loop    move.w    (a0)+,(a1)+
  2310.     dbra    d0,.Loop
  2311.     lea    ReadIo-MB(a3),a1
  2312.     move.l    ReadPort-MB(a3),14(a1)
  2313.  
  2314. ; Open translator
  2315.     Rbsr    L_NarInit
  2316.     lea    TranName-MB(a3),a1
  2317.     moveq    #0,d0
  2318.     jsr    OpenLib(a6)
  2319.     move.l    d0,TranBase-MB(a3)
  2320.     beq    OpNarE
  2321. * Restore Sami interrupts
  2322.     move.l    DosBase(a5),a6
  2323.     moveq    #50,d1
  2324.     jsr    -198(a6)
  2325.     clr.w    Sami_Flag-MB(a3)
  2326.     RBsr    L_Sami_Install
  2327. * Ok!
  2328.     movem.l    (sp)+,a3-a6
  2329.     rts
  2330.  
  2331. ;-----> Annule un speech précédent
  2332. OpNarCheck
  2333.     RBsr    L_NarStop
  2334.     movem.l    (sp)+,a3-a6
  2335.     rts
  2336. ;-----> Can't open narrator
  2337. OpNarE    movem.l    (sp)+,a3-a6
  2338. NoNar    moveq    #7,d0
  2339.     Rbra    L_Custom
  2340.  
  2341. ******* Init narrator (if here)!
  2342. L_NarInit    equ    4
  2343. L4    move.l    WriteIO-MB(a3),d0
  2344.     beq.s    .Skip
  2345.     move.l    d0,a1
  2346.     move.w    #150,48(a1)
  2347.     move.w    #110,50(a1)
  2348.     clr.w    52(a1)
  2349.     clr.w    54(a1)
  2350.     lea    Amaps-MB(a3),a0
  2351.     move.l    a0,56(a1)
  2352.     move.w    #4,60(a1)
  2353.     move.w    #63,62(a1)
  2354.     move.w    #22200,64(a1)
  2355. .Skip    rts
  2356.  
  2357. ******* SAY a$[,multi]
  2358. L_ISay2:    equ    5
  2359. L5    Rbsr    L_OpNar
  2360.     move.l    (a3)+,d7
  2361.     RBra    L_ISay
  2362. L_ISay1:    equ    6
  2363. L6    Rbsr    L_OpNar
  2364.     moveq    #0,d7    
  2365.     Rbra    L_ISay
  2366. L_ISay:        equ    7
  2367. L7    moveq    #%0000,d0
  2368.     Rbsr    L_StopDma
  2369.     Rbsr    L_VOnOf
  2370.     DLoad    a0
  2371.     clr.w    EnvOn-MB(a0)
  2372.     clr.w    Noise-MB(a0)
  2373.     move.l    (a3)+,a0
  2374.     moveq    #0,d0
  2375.     move.w    (a0)+,d0
  2376. * Phoneme?
  2377.     cmp.b    #"~",(a0)
  2378.     bne.s    ISayN
  2379.     addq.l    #1,a0
  2380.     move.l    Buffer(a5),a1
  2381.     move.w    d0,d1
  2382.     cmp.w    #1024,d1
  2383.     bcc    ISayN
  2384.     subq.w    #2,d1
  2385.     bmi.s    ISayN
  2386. ISayP    move.b    (a0)+,(a1)+
  2387.     dbra    d1,ISayP
  2388.     move.b    #"Q",(a1)+
  2389.     move.b    #"#",(a1)+
  2390.     move.b    #"U",(a1)+
  2391.     clr.b    (a1)+
  2392.     clr.b    (a1)+
  2393.     addq.w    #4,d0
  2394.     movem.l    a3/a6,-(sp)
  2395.     DLoad    a3
  2396.     bra.s    ISayNn
  2397. * Call TRANSLATOR
  2398. ISayN    move.l    Buffer(a5),a1
  2399.     move.l    a1,a2
  2400.     move.l    #1024,d1
  2401.     move.l    d1,d2
  2402.     lsr.w    #2,d2
  2403.     subq.w    #2,d2
  2404. ISayN1    clr.l    (a2)+
  2405.     dbra    d2,ISayN1
  2406.     movem.l    a3/a6,-(sp)
  2407.     DLoad    a3
  2408.     move.l    TranBase-MB(a3),a6
  2409.     jsr    Translate(a6)
  2410.     tst.w    d0
  2411.     bne.s    SayX
  2412.     move.l    #1024,d0
  2413. ISayNn
  2414.     Rbsr    L_Sami_remove
  2415.     move.l    WriteIO-MB(a3),a1
  2416.     move.w    #3,28(a1)
  2417.     move.l    d0,36(a1)
  2418.     move.l    Buffer(a5),40(a1)
  2419.     move.l    ExecBase,a6
  2420.     tst.w    d7
  2421.     bne.s    ISayA
  2422. ; Mode non multitache
  2423.     clr.b    66(a1)
  2424.     jsr    DoIO(a6)
  2425.     RBsr    L_Sami_install
  2426. SayX    movem.l    (sp)+,a3/a6
  2427.     moveq    #%1111,d0
  2428.     Rbsr    L_VOnOf
  2429.     rts
  2430. ; Mode multitache
  2431. ISayA    move.b    #1,66(a1)        Generer des mouths!
  2432.     jsr    SendIO(a6)
  2433.     movem.l    (sp)+,a3/a6
  2434.     rts
  2435. ******* SET TALK sex,mode,pitch,rate
  2436. L_ITalk        equ    8
  2437. L8    Rbsr    L_OpNar
  2438.     move.l    #EntNul,d0
  2439.     Dload    a1
  2440.     move.l    WriteIo-MB(a1),a1
  2441.     move.l    (a3)+,d1
  2442.     cmp.l    d0,d1
  2443.     beq.s    IRd1
  2444.     cmp.w    #40,d1
  2445.     Rbcs    L_IFonc
  2446.     cmp.w    #400,d1
  2447.     Rbhi    L_IFonc
  2448.     move.w    d1,48(a1)
  2449. IRd1    move.l    (a3)+,d1
  2450.     cmp.l    d0,d1
  2451.     beq.s    IRd2
  2452.     cmp.w    #65,d1
  2453.     Rbcs    L_IFonc
  2454.     cmp.w    #320,d1
  2455.     Rbhi    L_IFonc
  2456.     move.w    d1,50(a1)
  2457. IRd2    move.l    (a3)+,d1
  2458.     cmp.l    d0,d1
  2459.     beq.s    IRd3
  2460.     and.w    #$0001,d1
  2461.     move.w    d1,52(a1)
  2462. IRd3    move.l    (a3)+,d1
  2463.     cmp.l    d0,d1
  2464.     beq.s    IRd4
  2465.     and.w    #$0001,d1
  2466.     move.w    d1,54(a1)
  2467. IRd4    rts
  2468.  
  2469. ******* Narrator READ lips
  2470. L_LipsX        equ    9
  2471. L9    Dlea    ReadIo,a0
  2472.     moveq    #0,d2
  2473.     move.b    88(a0),d3
  2474.     ext.w    d3
  2475.     ext.l    d3
  2476.     rts
  2477. L_LipsY        equ    10
  2478. L10    Dlea    ReadIo,a0
  2479.     moveq    #0,d2
  2480.     move.b    89(a0),d3
  2481.     ext.w    d3
  2482.     ext.l    d3
  2483.     rts
  2484.  
  2485. ***********************************************************
  2486. *    MUSIC INSTRUCTION
  2487.  
  2488. *******    BELL
  2489. L_Bell0        equ    11
  2490. L11    moveq    #0,d3
  2491.     moveq    #70,d2
  2492.     moveq    #%1111,d1
  2493.     moveq    #1,d5
  2494.     Dlea    EnvBell,a0
  2495.     move.l    a0,d6
  2496.     Rbra    L_GoBel
  2497. L_Bell1        equ    12
  2498. L12    moveq    #0,d3
  2499.     move.l    (a3)+,d2
  2500.     moveq    #%1111,d1
  2501.     moveq    #1,d5
  2502.     Dlea    EnvBell,a0
  2503.     move.l    a0,d6
  2504.     Rbra    L_GoBel
  2505. ******* BOOM
  2506. L_Boom        equ    13
  2507. L13    moveq    #0,d3
  2508.     moveq    #36,d2
  2509.     moveq    #0,d5
  2510.     Dlea    EnvBoom,a0
  2511.     move.l    a0,d6
  2512.     Rbra    L_Shout
  2513. ******* SHOOT
  2514. L_Shoot        equ    14
  2515. L14    moveq    #0,d3
  2516.     moveq    #60,d2
  2517.     moveq    #0,d5
  2518.     Dlea    EnvShoot,a0
  2519.     move.l    a0,d6
  2520.     Rbra    L_Shout
  2521. * Gives a stereo effect
  2522. L_Shout:    equ    15
  2523. L15    moveq    #%0000,d0
  2524.     Rbsr    L_StopDma
  2525.     Rbsr    L_VOnOf
  2526.     moveq    #%1000,d1
  2527. Shot    movem.l    d0-d7,-(sp)
  2528.     Rbsr    L_GoShot
  2529.     movem.l    (sp)+,d0-d7
  2530.     addq.w    #1,d2
  2531.     lsr.w    #1,d1
  2532.     bcc.s    Shot
  2533.     rts
  2534.  
  2535. *******    VOLUME n
  2536. L_IVol1        equ    16
  2537. L16    move.l    (a3)+,d0
  2538.     moveq    #%1111,d1
  2539.     Rbsr    L_Vol
  2540.     Rbsr    L_MVol
  2541.     rts
  2542. ******* VOLUME voice,n
  2543. L_IVol2        equ    17
  2544. L17    move.l    (a3)+,d0
  2545.     move.l    (a3)+,d1
  2546.     Rbra    L_Vol
  2547. * Set voices volume level
  2548. L_Vol        equ    18
  2549. L18    cmp.l    #64,d0
  2550.     Rbcc    L_IFonc
  2551.     moveq    #0,d2
  2552.     Dlea    EnvBase,a0
  2553.     Dlea    Sami_int,a1
  2554. Vol1    btst    d2,d1
  2555.     beq.s    Vol2
  2556.     move.w    d0,EnvDVol(a0)
  2557.     tst.w    Sami_dvol(a1)
  2558.     bmi.s    Vol2
  2559.     move.w    d0,Sami_dvol(a1)
  2560. Vol2    lea    EnvLong(a0),a0
  2561.     lea    Sami_intl(a1),a1
  2562.     addq.w    #1,d2
  2563.     cmp.w    #4,d2
  2564.     bcs.s    Vol1
  2565.     rts
  2566.  
  2567. ******* Stops Narrator if it was playing in multitask mode!
  2568. L_NarStop    equ    19
  2569. L19    movem.l    a3/a6,-(sp)
  2570.     Dload    a3
  2571.     move.l    $4.w,a6
  2572.     move.l    WriteIo-MB(a3),d0
  2573.     beq.s    .Skip2
  2574.     move.l    d0,a1
  2575.     tst.b    66(a1)
  2576.     beq.s    .Skip2
  2577.     clr.b    66(a1)
  2578.     jsr    _LVOCheckIO(a6)
  2579.     tst.l    d0
  2580.     bne.s    .Skip1
  2581.     move.l    WriteIo-MB(a3),a1
  2582.     jsr    _LVOAbortIO(a6)
  2583. .Skip1    move.l    WriteIo-MB(a3),a1
  2584.     jsr    _LVOWaitIO(a6)
  2585.     Rbsr    L_Sami_Install
  2586. .Skip2    movem.l    (sp)+,a3/a6
  2587.     rts
  2588.  
  2589. *******    PLAY note,length
  2590. L_IPlay2    equ    20
  2591. L20    move.l    (a3)+,d3
  2592.     Rbmi    L_IFonc
  2593.     move.l    (a3)+,d2
  2594.     moveq    #%1111,d1
  2595.     moveq    #-1,d5
  2596.     moveq    #0,d6
  2597.     Rbra    L_GoBel
  2598. ******* Play voice,note,length
  2599. L_IPlay3    equ    21
  2600. L21    move.l    (a3)+,d3
  2601.     Rbmi    L_IFonc
  2602.     move.l    (a3)+,d2
  2603.     move.l    (a3)+,d1
  2604.     moveq    #-1,d5
  2605.     moveq    #0,d6
  2606.     Rbra    L_GoBel
  2607. L_GoBel        equ    22
  2608. L22    cmp.l    #96,d2            * <96?
  2609.     Rbhi    L_IFonc
  2610.     move.w    d1,d0            * Stop voices
  2611.     eor.w    #$000F,d0
  2612.     Rbsr    L_StopDma
  2613.     Rbsr    L_VOnOf
  2614.     Rbra    L_GoShot
  2615. L_GoShot    equ    23
  2616. L23    move.l    a3,-(sp)
  2617.     lea    Circuits,a2
  2618.     Dload    a3
  2619.     move.w    EnvOn-MB(a3),d7
  2620.     clr.w    EnvOn-MB(a3)
  2621.     move.w    #$8000,Sami_Bits-MB(a3)
  2622. * Explores all 4 voices
  2623.     moveq    #0,d0
  2624.     move.w    d1,d4
  2625.     moveq    #3,d1
  2626. IPl1    btst    d1,d4
  2627.     beq.s    IPl2
  2628.     Rbsr    L_VPlay
  2629. IPl2    dbra    d1,IPl1
  2630. ******* Start!
  2631. IPlX    Rbsr    L_DmaWait
  2632.     bset    #15,d0
  2633.     move.w    d0,DmaCon(a2)
  2634.     move.w    Sami_bits-MB(a3),IntEna(a2)
  2635.     move.w    d7,EnvOn-MB(a3)
  2636.     move.l    (sp)+,a3
  2637. * Wait?
  2638.     tst.l    d3
  2639.     beq.s    IPlX1
  2640.     Rjsr    L_WaitRout
  2641. IPlX1    rts
  2642.  
  2643. ******* Play voice D1: WAVE orSAMPLE
  2644. L_VPlay        equ    24
  2645. L24    movem.l    d0-d6/a0-a2,-(sp)
  2646.  
  2647.     moveq    #0,d3
  2648.     bset    d1,d3
  2649.     move.w    d3,DmaCon(a2)        * Stop voice
  2650.     lsl.w    #7,d3
  2651.     move.w    d3,IntEna(a2)        * Stop interrupts
  2652.     bclr    d1,Noise-MB(a3)        * No more random
  2653.     
  2654.     tst.w    d2
  2655.     beq    VSil
  2656.     addq.w    #3,d2
  2657.     move.w    d5,d0            * Forced wave? (bell)
  2658.     bpl.s    VPl0
  2659.     move.w    d1,d0            * Wave or Sample?
  2660.     lsl.w    #1,d0
  2661.     lea    Waves-MB(a3),a0
  2662.     move.w    0(a0,d0.w),d0
  2663.     bmi    VPl2
  2664.  
  2665. * Play WAVE!
  2666. VPl0    beq    VPl4
  2667.     lea    $a0(a2),a2
  2668.     move.w    d1,d3
  2669.     lsl.w    #4,d3
  2670.     add.w    d3,a2            * a2-> I/O
  2671.     movem.l    d1-d3/a2,-(sp)
  2672.     move.w    d0,d1
  2673.     Rbsr    L_WaveAd
  2674.     Rbeq    L_WNDef
  2675.     move.l    a2,a1
  2676.     movem.l    (sp)+,d1-d3/a2
  2677.     pea    WaveEnv(a1)
  2678.     lea    WaveDeb(a1),a1
  2679.     subq.w    #1,d2
  2680.     move.w    d2,d3
  2681.     ext.l    d3
  2682.     divu    #12,d3
  2683.     lsl.w    #2,d3
  2684.     lea    TFreq-MB(a3),a0
  2685.     add.w    d3,a0
  2686.     add.w    (a0)+,a1
  2687.     move.l    a1,(a2)            * AudAd
  2688.     move.w    (a0)+,d3
  2689.     move.w    d3,4(a2)        * AudLen
  2690.     lsl.w    #1,d3
  2691.     lea    TNotes-MB(a3),a1
  2692.     lsl.w    #1,d2
  2693.     mulu    0(a1,d2.w),d3
  2694.     move.l    MusClock-MB(a3),d2
  2695.     divu    d3,d2
  2696.     cmp.w    #124,d2
  2697.     bcc.s    VPl1
  2698.     moveq    #124,d2
  2699. VPl1:    move.w    d2,6(a2)        * AudPer
  2700. * Start enveloppe 
  2701.     move.l    (sp)+,d5
  2702.     tst.l    d6            * Fixed enveloppe? (bell / shoot)
  2703.     bne.s    VPl1a
  2704.     move.l    d5,d6
  2705. VPl1a    lea    EnvBase-MB(a3),a0    
  2706.     move.w    d1,d0
  2707.     mulu    #EnvLong,d0
  2708.     add.w    d0,a0
  2709.     move.l    d6,EnvAd(a0)
  2710.     move.l    d6,EnvDeb(a0)
  2711.     clr.w    EnvVol(a0)
  2712.     Rbsr    L_MuIntE
  2713.     movem.l    (sp)+,a0-a2/d0-d6
  2714.     bset    d1,d0
  2715.     bset    d1,d7
  2716.     rts
  2717. ******* Silence!
  2718. VSil    moveq    #0,d0
  2719.     bset    d1,d0
  2720.     move.w    d0,DmaCon(a2)
  2721.     movem.l    (sp)+,a0-a2/d0-d6
  2722.     bclr    d1,d7
  2723.     rts    
  2724. ******* Play SAMPLE
  2725. VPl2    move.l    a2,-(sp)
  2726.     move.w    d2,-(sp)
  2727.     neg.w    d0
  2728.     Rbsr    L_GetSam
  2729.     move.w    (sp)+,d0
  2730.     move.l    (sp)+,a2
  2731.     moveq    #0,d6
  2732. VPl3    lea    TNotes-MB(a3),a0
  2733.     lsl.w    #1,d0
  2734.     mulu    -2(a0,d0.w),d3
  2735.     divu    #440,d3
  2736.     and.l    #$0000FFFF,d3
  2737.     Rbra    L_SPl0
  2738. ******* Play NOISE
  2739. VPl4    bset    d1,Noise-MB(a3)
  2740.     move.w    d2,d0
  2741.     move.l    WaveBase-MB(a3),a1
  2742.     lea    WaveEnv(a1),a0
  2743.     lea    WaveDeb(a1),a1
  2744.     move.l    #LNoise,d2
  2745.     move.l    #2000,d3
  2746.     tst.l    d6
  2747.     bne.s    VPl3
  2748.     move.l    a0,d6
  2749.     bset    #0,d6
  2750.     bra.s    VPl3
  2751.  
  2752. ******* PLAY OFF (voice)
  2753. L_IPlOf0    equ    25
  2754. L25    moveq    #%1111,d0
  2755.     Rbra    L_PlOf
  2756. L_IPlOf1    equ    26
  2757. L26    move.l    (a3)+,d0
  2758.     Rbra    L_Plof
  2759. L_PlOf        equ    27
  2760. L27    move.l    a3,-(sp)
  2761.     Dload    a3
  2762.     Rbsr    L_EnvOff
  2763.     move.l    (sp)+,a3
  2764.     rts
  2765.  
  2766. ******* Attente DMA
  2767. L_DmaWait    equ    28
  2768. L28    movem.l    d2-d3,-(sp)
  2769.  
  2770. ; A modifier!!! Demander les caracteristiques du DMA!!!
  2771. ;    move.w    #$200,d0
  2772. ;.loop    nop
  2773. ;    dbra    d0,.loop
  2774.  
  2775. .wait    moveq    #4,d3        
  2776. .wai2    move.b    $dff006,d2    
  2777. .wai3    cmp.b    $dff006,d2    
  2778.     beq.s    .wai3
  2779.     dbf    d3,.wai2    
  2780.     moveq    #8,d2
  2781. .wai4    dbf    d2,.wai4
  2782.  
  2783.     movem.l    (sp)+,d2-d3
  2784.     rts
  2785.  
  2786. ***********************************************************
  2787. *    SAMPLE INSTRUCTIONS
  2788.  
  2789. *******    SAM BANK n
  2790. L_ISBank    equ    29
  2791. L29    move.l    (a3)+,d0
  2792.     Rbls    L_IFonc
  2793.     cmp.l    #16,d0
  2794.     Rbhi    L_IFonc
  2795.     Dlea    SamBank,a0
  2796.     move.w    d0,(a0)
  2797.     rts
  2798. ******* SAMLOOP ON
  2799. L_ISLOn1    equ    30
  2800. L30    moveq    #0,d0
  2801.     move.l    (a3)+,d1
  2802.     Rbra    L_Sl0
  2803.  
  2804. ******* STOP DMA / INTERUPTS
  2805. *    D0= value
  2806. L_StopDma    equ    31
  2807. L31    move.w    d0,-(sp)
  2808.     eor.w    #%1111,d0
  2809.     move.w    d0,Circuits+DmaCon
  2810.     lsl.w    #7,d0
  2811.     move.w    d0,Circuits+IntEna
  2812.     move.w    (sp)+,d0
  2813.     RBra    L_DmaWait
  2814.  
  2815. L_ISLOn0    equ    32
  2816. L32    moveq    #0,d0
  2817.     moveq    #%1111,d1
  2818.     Rbra    L_Sl0
  2819.  
  2820. ******* SAMLOOP OFF
  2821. L_ISLOf1    equ    33
  2822. L33    moveq    #-1,d0
  2823.     move.l    (a3)+,d1
  2824.     Rbra    L_Sl0
  2825. L_ISLOf0    equ    34
  2826. L34    moveq    #-1,d0
  2827.     moveq    #%1111,d1
  2828.     Rbra    L_SL0
  2829. L_SL0        equ    35
  2830. L35    moveq    #0,d2
  2831.     Dlea    Sami_int,a0
  2832.     Dlea    SamLoops+1,a1
  2833. Sl1    btst    d2,d1
  2834.     beq.s    Sl2
  2835.     bclr    d2,(a1)
  2836.     move.l    d0,Sami_rpos(a0)
  2837.     bne.s    Sl2
  2838.     bset    d2,(a1)
  2839. Sl2    lea    Sami_intl(a0),a0
  2840.     addq.w    #1,d2
  2841.     cmp.w    #4,d2
  2842.     bcs.s    Sl1
  2843.     rts
  2844.  
  2845. ******* NOISE TO voice
  2846. L_INoTo        equ    36
  2847. L36    move.l    (a3)+,d1
  2848.     moveq    #0,d0
  2849.     Rbra    L_ISmt
  2850. ******* SAMPLE n TO voice
  2851. L_ISamTo    equ    37
  2852. L37    move.l    4(a3),d0
  2853.     Rbsr    L_GetSam
  2854.     move.l    (a3)+,d1
  2855.     move.l    (a3)+,d0
  2856.     neg.w    d0
  2857.     Rbra    L_Ismt
  2858. * Poke D1-> waves
  2859. L_ISmt        equ    38
  2860. L38    Dlea    Waves,a0
  2861.     moveq    #0,d2
  2862. ISmt1    btst    d2,d1
  2863.     beq.s    ISmt2
  2864.     move.w    d0,(a0)
  2865. ISmt2    addq.l    #2,a0
  2866.     addq.w    #1,d2
  2867.     cmp.w    #4,d2
  2868.     bcs.s    ISmt1
  2869.     rts
  2870.  
  2871. ******* SAM PLAY number
  2872. L_ISam1        equ    39
  2873. L39    move.l    (a3)+,d0
  2874.     Rbsr    L_GetSam
  2875.     moveq    #%1111,d1
  2876.     Rbra    L_GoSam
  2877. ******* SAM PLAY voix,number
  2878. L_ISam2        equ    40
  2879. L40    move.l    (a3)+,d0
  2880.     Rbsr    L_GetSam
  2881.     move.l    (a3)+,d1
  2882.     Rbra    L_GoSam
  2883. ******* SAM PLAY voix,number,frequence
  2884. L_ISam3        equ    41
  2885. L41    move.l    4(a3),d0
  2886.     Rbsr    L_GetSam
  2887.     move.l    (a3)+,d3
  2888.     cmp.l    #500,d3
  2889.     Rble    L_IFonc
  2890.     addq.l    #4,a3
  2891.     move.l    (a3)+,d1    
  2892.     Rbra    L_GoSam
  2893. ******* SAM RAW voice,ad,length,freq
  2894. L_ISamR        equ    42
  2895. L42    move.l    (a3)+,d3
  2896.     cmp.l    #500,d3
  2897.     Rble    L_IFonc
  2898.     move.l    (a3)+,d2
  2899.     cmp.l    #256,d2
  2900.     Rble    L_IFonc
  2901.     move.l    (a3)+,a1
  2902.     move.l    (a3)+,d1
  2903.     Rbra    L_GoSam
  2904. L_GoSam:    equ    43
  2905. L43    move.l    a3,-(sp)
  2906.     Dload    a3
  2907.  
  2908.     move.w    d1,d0
  2909.     eor.w    #$000F,d0
  2910.     Rbsr    L_StopDma
  2911.     Rbsr    L_VOnOf    
  2912.  
  2913.     lea    Circuits,a2
  2914.     move.w    EnvOn-MB(a3),d7
  2915.     clr.w    EnvOn-MB(a3)
  2916.     move.w    #$8000,Sami_bits-MB(a3)
  2917. * Do all voices
  2918.     moveq    #0,d0
  2919.     move.w    d1,d4
  2920.     moveq    #3,d1
  2921. ISp2b    btst    d1,d4
  2922.     beq.s    ISp2c
  2923.     Rbsr    L_SPlay
  2924. ISp2c    dbra    d1,ISp2b
  2925. * Start!
  2926. ISpX    
  2927.     Rbsr    L_DmaWait
  2928.     bset    #15,d0
  2929.     move.w    d0,DmaCon(a2)
  2930.     move.w    Sami_bits-MB(a3),IntEna(a2)
  2931.     move.w    d7,EnvOn-MB(a3)
  2932.     move.l    (sp)+,a3
  2933.     rts
  2934.     
  2935. ******* Find a sample -> A0
  2936. L_GetSam    equ    44
  2937. L44    move.l    d0,-(sp)
  2938.     Dload    a0
  2939.     move.w    SamBank-MB(a0),d0
  2940.     ext.l    d0
  2941.     Rbeq    L_IFonc
  2942.     move.l    d1,-(sp)
  2943.     Rjsr    L_Bnk.GetAdr
  2944.     Rbeq    L_BNSam
  2945.     move.l    (sp)+,d1
  2946.     move.l    -8(a0),d0
  2947.     cmp.l    #"Samp",d0
  2948.     Rbne    L_BNSam
  2949. * Get sample characteristics1
  2950.     move.l    (sp)+,d0
  2951.     Rbls    L_IFonc
  2952.     cmp.w    (a0),d0
  2953.     Rbhi    L_SNDef
  2954.     lsl.w    #2,d0
  2955.     move.l    2-4(a0,d0.w),d0
  2956.     Rbeq    L_SNDef
  2957.     add.l    d0,a0
  2958.     moveq    #0,d3
  2959.     move.w    8(a0),d3
  2960.     move.l    10(a0),d2
  2961.     lea    14(a0),a1
  2962.     rts
  2963.  
  2964. *********************************************************************
  2965. *    SLOAD fichier,adresse,longueur
  2966. L_Sload        equ    45
  2967. L45    move.l    (a3)+,d3        Length
  2968.     RBmi    L_IFonc    
  2969.     move.l    (a3)+,d0        Adress (or bank)
  2970.     RJsr    L_Bnk.OrAdr
  2971.     move.l    d0,d2
  2972.     move.l    (a3)+,d0        File
  2973.     cmp.l    #10,d0
  2974.     Rbcc    L_IFonc
  2975.     subq.l    #1,d0
  2976.     Rbmi    L_IFonc
  2977.     mulu    #TFiche,d0
  2978.     lea    Fichiers(a5),a2
  2979.     add.w    d0,a2
  2980.     move.l    Fha(a2),d1
  2981.     RBeq    L_IFonc
  2982.     btst    #2,FhT(a2)
  2983.     Rbne    L_IFonc
  2984. * Load the data
  2985.     move.l    a6,-(sp)
  2986.     move.l    DosBase(a5),a6
  2987.     jsr    -42(a6)            DosRead
  2988.     move.l    (sp)+,a6
  2989.     tst.l    d0
  2990.     RBmi    L_IDError
  2991.     rts
  2992.  
  2993. ******* SAMPLAY routine
  2994. *    A1= Sample
  2995. *    D3= Freq
  2996. *    D2= Long
  2997. *    D1= Voice
  2998. L_SPlay:    equ    46
  2999. L46    movem.l    d0-d6/a0-a2,-(sp)
  3000.     bclr    d1,Noise-MB(a3)
  3001.     moveq    #0,d6
  3002.     Rbra    L_SPl0
  3003.  
  3004. L_SPl0        equ    47
  3005. L47
  3006.     movem.l    a4,-(sp)
  3007.  
  3008.     moveq    #0,d0
  3009.     bset    d1,d0            * Stop voice
  3010.     move.w    d0,DmaCon(a2)
  3011.  
  3012.     lea    Sami_int-MB(a3),a4
  3013.     move.w    #Sami_intl,d0
  3014.     mulu    d1,d0
  3015.     add.w    d0,a4            * a4-> Sami interrupts
  3016.     move.w    Sami_bit(a4),IntEna(a2)    * No more interrupts
  3017.  
  3018.     lea    EnvBase-MB(a3),a0    * Enveloppe
  3019.     move.w    d1,d0
  3020.     mulu    #EnvLong,d0
  3021.     add.w    d0,a0
  3022.  
  3023.     lea    $a0(a2),a2
  3024.     move.w    d1,d4
  3025.     lsl.w    #4,d4
  3026.     add.w    d4,a2            * a2-> I/O
  3027.  
  3028.     move.w    #1,$4(a2)
  3029.     move.l    a1,Sami_adr(a4)            * Adresse
  3030.     move.l    d2,Sami_long(a4)        * Longueur
  3031.     clr.l    Sami_pos(a4)            * Position
  3032.     clr.l    Sami_rpos(a4)            * Sam loop on?
  3033.     btst    d1,SamLoops+1-MB(a3)
  3034.     bne.s    .skipa
  3035.     subq.l    #1,Sami_rpos(a4)
  3036. .skipa    clr.l    Sami_radr(a4)            * Pas de double buffer
  3037.     
  3038.     move.l    d6,d5
  3039.     move.l    MusClock-MB(a3),d6
  3040.     bsr    Div32
  3041.     cmp.l    #124,d0
  3042.     bcc.s    .skip0
  3043.     moveq    #124,d0
  3044. .skip0    move.w    d0,6(a2)            * AudPer
  3045.  
  3046.     bclr    d1,d7
  3047.     move.w    EnvDVol(a0),Sami_dvol(a4)    * Volume, sauf si 
  3048.     tst.l    d5                  une enveloppe est
  3049.     beq.s    .skip1                  definie
  3050.     clr.l    Sami_rpos(a4)
  3051.     bclr    #0,d5
  3052.     bne.s    .skipb
  3053.     subq.l    #1,Sami_rpos(a4)
  3054. .skipb    bset    d1,d7
  3055.     move.w    #-1,Sami_dvol(a4)
  3056.     move.l    d5,EnvAd(a0)
  3057.     move.l    d5,EnvDeb(a0)
  3058.     clr.w    EnvVol(a0)
  3059.     Rbsr    L_MuIntE
  3060.  
  3061. .skip1    move.w    Sami_bit(a4),d0
  3062.     or.w    d0,Sami_bits-MB(a3)
  3063.  
  3064. * Va demarrer le son...
  3065.     lea    Circuits,a0
  3066.     move.l    a4,a1
  3067.     move.l    Sami_Handad-MB(a3),a2
  3068.     jsr    (a2)
  3069. * Fini!
  3070.     move.l    (sp)+,a4
  3071.     movem.l    (sp)+,d0-d6/a0-a2
  3072.     bset    d1,d0
  3073.     rts
  3074.  
  3075. * Division 32 bits
  3076. * D6/D3 -> D0
  3077. Div32    movem.l    d1/d3/d4/d5/d6,-(sp)
  3078.     moveq     #31,d5
  3079.         moveq     #-1,d4
  3080.         clr.l     d1
  3081. dv2:    lsl.l     #1,d6
  3082.         roxl.l     #1,d1
  3083.         cmp.l     d3,d1
  3084.         bcs.s     dv1
  3085.         sub.l     d3,d1
  3086.         lsr     #1,d4
  3087. dv1:    roxl.l     #1,d0
  3088.         dbra     d5,dv2
  3089.     movem.l    (sp)+,d1/d3/d4/d5/d6
  3090.     rts
  3091.  
  3092. ***********************************************************
  3093. *    WAVE INSTRUCTION SET
  3094.  
  3095. *******    WAVE n TO n
  3096. L_IWave:    equ    48
  3097. L48    move.l    4(a3),d1
  3098.     Rbmi    L_IFonc
  3099.     Rbsr    L_WaveAd
  3100.     Rbeq    L_WNDef
  3101.     move.l    (a3)+,d1
  3102.     move.l    (a3)+,d0
  3103.     Rbra    L_ISmt
  3104. *******    SET WAVE n,a$
  3105. L_ISWave:    equ    49
  3106. L49    move.l    (a3)+,a1
  3107.     move.w    (a1)+,d1
  3108.     cmp.w    #256,d1
  3109.     Rbcs    L_STSho
  3110.     move.l    (a3)+,d1
  3111.     Rbls    L_IFonc
  3112.     move.l    a3,-(sp)
  3113.     Dload    a3
  3114.     Rbsr    L_NeWave
  3115.     Rbne    L_IOOMem
  3116.     move.l    (sp)+,a3
  3117.     rts
  3118. *******    DEL WAVE 
  3119. L_IDWave1    equ    50
  3120. L50    move.l    (a3)+,d1
  3121.     Rbmi    L_IFonc
  3122.     Rbeq    L_W0Res
  3123.     cmp.l    #1,d1
  3124.     Rbeq    L_W0Res
  3125.     move.l    a3,-(sp)
  3126.     DLoad    a3
  3127.     moveq    #%1111,d0
  3128.     Rbsr    L_EnvOff
  3129.     Rbsr    L_WaveAd
  3130.     Rbeq    L_WNDef
  3131.     Rbsr    L_WaveDel
  3132.     Rbsr    L_NoWave
  3133.     move.l    (sp)+,a3
  3134.     rts
  3135. *******    SET ENVEL n,n TO n,v
  3136. L_ISEnv        equ    51
  3137. L51    move.l    (a3)+,d4
  3138.     cmp.l    #64,d4
  3139.     Rbcc    L_IFonc
  3140.     move.l    (a3)+,d3
  3141.     move.l    (a3)+,d5
  3142.     Rbmi    L_IFonc
  3143.     cmp.l    #7,d5
  3144.     Rbcc    L_IFonc
  3145.     move.l    (a3)+,d1
  3146.     Rbmi    L_IFonc
  3147.     tst.w    d5
  3148.     bne.s    ISe1
  3149.     tst.w    d3
  3150.     Rbls    L_IFonc
  3151. ISe1    move.l    a3,-(sp)
  3152.     Dload    a3
  3153.     Rbsr    L_WaveAd
  3154.     Rbeq    L_WNDef
  3155.     lsl.w    #2,d5
  3156.     lea    WaveEnv(a2,d5.w),a2
  3157.     move.w    d3,(a2)+
  3158.     move.w    d4,(a2)+
  3159.     clr.w    (a2)
  3160.     move.l    (sp)+,a3
  3161.     rts
  3162. ******* RAZ WAVES
  3163. L_RazWave    equ    52
  3164. L52    movem.l    a2/d0-d2,-(sp)
  3165.     moveq    #%1111,d0
  3166.     Rbsr    L_EnvOff        * Stop all voices
  3167.     lea    WaveBase-MB(a3),a2    * Erase all instruments
  3168.     move.l    a2,d2
  3169. RzW1    move.l    d2,a2
  3170.     move.l    (a2),d0
  3171.     beq.s    RzW2
  3172.     move.l    d0,a2
  3173.     Rbsr    L_WaveDel
  3174.     bra.s    RzW1
  3175. RzW2    Rbsr    L_NoWave
  3176.     movem.l    (sp)+,a2/d0-d2
  3177.     rts
  3178. * Plus de Waves speciales
  3179. L_NoWave    equ    53
  3180. L53    Dlea    Waves,a0        * Default waves
  3181.     move.w    #1,(a0)+
  3182.     move.w    #1,(a0)+
  3183.     move.w    #1,(a0)+
  3184.     move.w    #1,(a0)+
  3185.     rts
  3186.  
  3187. ******* NEW WAVES
  3188. *    A1= Array address
  3189. *    D1= # to create
  3190. L_NeWave:    equ    54
  3191. L54    movem.l    d1-d7/a1-a2,-(sp)
  3192. NeW0    Rbsr    L_WaveAd
  3193.     beq.s    NeW1
  3194.     moveq    #%1111,d0
  3195.     Rbsr    L_EnvOff
  3196.     Rbsr    L_WaveDel
  3197.     bra.s    NeW0
  3198. NeW1    move.l    #WaveLong,d0
  3199.     RJsr    L_RamChip
  3200.     beq.s    NeWE
  3201.     move.l    d0,(a2)
  3202.     move.l    d0,a2
  3203.     move.w    d1,WaveNb(a2)
  3204. * Copy default ADSR
  3205.     move.l    a1,-(sp)
  3206.     lea    EnvDef-MB(a3),a0
  3207.     lea    WaveEnv(a2),a1
  3208. NeW3    move.l    (a0)+,(a1)+
  3209.     bne.s    NeW3
  3210.     move.l    (sp)+,a1
  3211. * Full wave: 256 bytes
  3212.     lea    WaveDeb(a2),a2
  3213.     move.l    a2,a0
  3214.     moveq    #256/4-1,d0
  3215. NeW2    move.l    (a1)+,(a0)+
  3216.     dbra    d0,NeW2
  3217. * 1/2
  3218.     move.l    a2,a1
  3219.     move.l    a0,a2
  3220.     moveq    #127,d0
  3221.     bsr    NewRout
  3222. * 1/4
  3223.     move.l    a2,a1
  3224.     move.l    a0,a2
  3225.     moveq    #63,d0
  3226.     bsr    NewRout
  3227. * 1/8
  3228.     move.l    a2,a1    
  3229.     move.l    a0,a2
  3230.     moveq    #31,d0
  3231.     bsr    NewRout
  3232. * 1/16
  3233.     move.l    a2,a1
  3234.     move.l    a0,a2
  3235.     moveq    #15,d0
  3236.     bsr    NewRout
  3237. * 1/32
  3238.     move.l    a2,a1
  3239.     move.l    a0,a2
  3240.     moveq    #7,d0
  3241.     bsr    NewRout
  3242. * 1/64
  3243.     move.l    a2,a1
  3244.     move.l    a0,a2
  3245.     moveq    #3,d0
  3246.     bsr    NewRout
  3247. ******* No error
  3248.     moveq    #0,d0
  3249. NeWx    movem.l    (sp)+,d1-d7/a1-a2
  3250.     rts
  3251. ******* Out of mem
  3252. NeWE    moveq    #-1,d0
  3253.     bra.s    NeWx
  3254. ******* Divide a sample by 2
  3255. NewRout    move.b    (a1)+,d1
  3256.     ext.w    d1
  3257.     move.b    (a1)+,d2
  3258.     ext.w    d2
  3259.     add.w    d2,d1
  3260.     asr.w    #1,d1
  3261.     move.b    d1,(a0)+
  3262.     dbra    d0,NewRout
  3263.     rts
  3264.  
  3265. ******* Get a wave address
  3266. L_WaveAd:    equ    55
  3267. L55    moveq    #0,d2
  3268.     Dlea    WaveBase,a2
  3269.     move.l    (a2),d0
  3270.     beq.s    WAd2
  3271. WAd1    move.l    a2,d2
  3272.     move.l    d0,a2
  3273.     cmp.w    WaveNb(a2),d1
  3274.     beq.s    WAd3
  3275.     move.l    (a2),d0
  3276.     bne.s    WAd1
  3277. WAd2    moveq    #0,d0
  3278.     rts
  3279. WAd3    moveq    #-1,d0
  3280.     rts
  3281.  
  3282. ******* Deletion of a WAVE (A2)-D2
  3283. L_WaveDel    equ    56
  3284. L56    movem.l    a0-a2/d0-d2,-(sp)
  3285.     move.w    WaveNb(a2),d1
  3286.     move.l    d2,a0
  3287.     move.l    (a2),(a0)
  3288.     move.l    #WaveLong,d0
  3289.     move.l    a2,a1
  3290.     Rjsr    L_RamFree
  3291.     movem.l    (sp)+,a0-a2/d0-d2
  3292.     rts
  3293.  
  3294. ***********************************************************
  3295. *    STOP SAMPLES INTERRUPTS
  3296. L_Sami_stop    equ    57
  3297. L57    move.w    #%0000011110000000,d0
  3298.     move.w    d0,Circuits+IntEna
  3299.     move.w    d0,Circuits+IntReq
  3300.     rts
  3301.  
  3302. ***********************************************************
  3303. *    ENVELOPPES 
  3304.  
  3305. ***********************************************************
  3306. *    STOP ENVELOPPE D0
  3307. L_EnvOff    equ    58
  3308. L58    movem.l    d0-d3/a0,-(sp)
  3309.     move.w    EnvOn-MB(a3),d1
  3310.     clr.w    EnvOn-MB(a3)
  3311.     moveq    #0,d3
  3312.     lea    Circuits,a0
  3313.     moveq    #0,d2
  3314. EOf1    btst    d2,d0
  3315.     beq.s    EOf2
  3316.     bclr    d2,d1
  3317.     beq.s    EOf2
  3318.     bset    d2,d3
  3319.     move.w    #2,$a4(a0)
  3320.     clr.w    $a8(a0)
  3321. EOf2    lea    $10(a0),a0
  3322.     addq.w    #1,d2
  3323.     cmp.w    #4,d2
  3324.     bcs.s    EOf1
  3325.     move.w    d1,EnvOn-MB(a3)
  3326.     move.w    d3,MuReStart-MB(a3)
  3327.     movem.l    (sp)+,d0-d3/a0
  3328.     rts
  3329.     
  3330. ******* Next enveloppe
  3331. L_MuIntE    equ    59
  3332. L59    move.l    EnvAd(a0),a1
  3333. MuIe0    move.w    (a1)+,d3
  3334.     beq.s    MuIntS
  3335.     bmi.s    MuIe1
  3336.     move.w    d3,EnvNb(a0)
  3337.     move.w    EnvDVol(a0),d4
  3338.     mulu    (a1)+,d4
  3339.     lsr.w    #6,d4
  3340.     sub.w    EnvVol(a0),d4
  3341.     ext.l    d4
  3342.     lsl.w    #8,d4
  3343.     divs    d3,d4
  3344.     ext.l    d4
  3345.     lsl.l    #8,d4
  3346.     move.l    d4,EnvDelta(a0)
  3347.     clr.w    EnvVol+2(a0)
  3348.     move.l    a1,EnvAd(a0)
  3349.     rts
  3350. * Loop
  3351. MuIe1    move.l    EnvDeb(a0),a1
  3352.     bra.s    MuIe0
  3353. * End of a voice
  3354. MuIntS    bset    d1,d5
  3355.     bclr    d1,d0
  3356.     bclr    d1,Noise-MB(a3)
  3357. * Restarts the music
  3358.     bset    d1,MuReStart+1-MB(a3)
  3359.     rts
  3360.  
  3361. ******************************************************************
  3362. *    MUSIC
  3363.  
  3364. ******* Music initialisation
  3365. L_MuInit:    equ    60
  3366. L60    clr.l    MuBase-MB(a3)
  3367.     clr.w    MuNumber-MB(a3)
  3368.     move.l    #$DFF0A0,MuChip0-MB(a3)
  3369.     move.l    #$DFF0B0,MuChip1-MB(a3)
  3370.     move.l    #$DFF0C0,MuChip2-MB(a3)
  3371.     move.l    #$DFF0D0,MuChip3-MB(a3)
  3372.     move.w    #$000F,MuDMAsk-MB(a3)
  3373.     clr.w    MuReStart-MB(a3)
  3374.     Rbra    L_MOff
  3375.  
  3376. ******* MUSIC OFF-> Stops all musics
  3377. L_IMuSOff    equ    61
  3378. L61    movem.l    a0-a3/d0-d1,-(sp)
  3379.     Dload    a3
  3380.     clr.l    MuBase-MB(a3)
  3381.     clr.w    MuNumber-MB(a3)
  3382.     Rbsr    L_MOff
  3383.     movem.l    (sp)+,a0-a3/d0-d1
  3384.     rts
  3385.  
  3386. ******* MUSIC STOP-> Stops current music
  3387. L_IMuStop    equ    62
  3388. L62    movem.l    a0-a3/d0-d1,-(sp)
  3389.     Dload    a3
  3390.     move.l    MuBase-MB(a3),d0
  3391.     beq.s    IStp
  3392.     clr.w    MuBase-MB(a3)
  3393.     move.l    d0,a0
  3394.     clr.w    VoiCpt0(a0)
  3395.     clr.w    VoiCpt1(a0)
  3396.     clr.w    VoiCpt2(a0)
  3397.     clr.w    VoiCpt3(a0)
  3398.     move.l    d0,MuBase-MB(a3)
  3399. IStp    movem.l    (sp)+,a0-a3/d0-d1
  3400.     rts
  3401.  
  3402. ******* MUSIC VOLUME
  3403. L_IMVol        equ    63
  3404. L63    move.l    (a3)+,d0
  3405.     cmp.l    #64,d0
  3406.     Rbcs    L_MVol
  3407.     Rbcc    L_IFonc
  3408. * Set volume
  3409. L_MVol        equ    64
  3410. L64    and.w    #63,d0
  3411.     Dload    a0
  3412.     move.w    d0,MuVolume-MB(a0)
  3413.     move.l    MuBase-MB(a0),d4
  3414.     beq.s    MVol3
  3415.     clr.l    MuBase-MB(a0)
  3416.     lea    MuBuffer-MB(a0),a1
  3417.     move.w    MuNumber-MB(a0),d1
  3418. MVol0    move.l    a1,a2
  3419.     moveq    #3,d2
  3420. MVol1    move.w    VoiDVol(a2),d3
  3421.     mulu    d0,d3
  3422.     lsr.w    #6,d3
  3423.     move.w    d3,VoiVol(a2)
  3424.     lea    VoiLong(a2),a2
  3425.     dbra    d2,MVol1
  3426. MVol2    lea    MuLong(a1),a1
  3427.     subq.w    #1,d1
  3428.     bne.s    MVol0
  3429.     move.l    d4,MuBase-MB(a0)
  3430. MVol3    rts
  3431.  
  3432. ******* VOICE ON/OFF Voices
  3433. L_IVoice    equ    65
  3434. L65    move.l    (a3)+,d0
  3435.     and.w    #$000F,d0
  3436.     move.l    a3,-(sp)
  3437.     Dload    a3
  3438.     Rbsr    L_VOnOf
  3439.     movem.l    (sp)+,a3
  3440.     rts
  3441.  
  3442. ******* Start / Stop voices D0
  3443. L_VOnOf        equ    66
  3444. L66    movem.l    d0-d5/a0-a3,-(sp)
  3445.     move.w    d0,d4
  3446.     Dload    a3
  3447.     move.l    MuBase-MB(a3),d1
  3448.     beq.s    VooX
  3449.     clr.l    MuBase-MB(a3)
  3450.     move.l    d1,a1
  3451.     move.l    d1,a2
  3452.     move.w    MuDMAsk-MB(a3),d1
  3453.     move.w    d0,MuDMAsk-MB(a3)
  3454.     move.l    WaveBase-MB(a3),a0
  3455.     lea    WaveDeb(a0),a0
  3456.     move.l    a0,d3
  3457.     lea    MuChip0-MB(a3),a0
  3458.     moveq    #0,d2
  3459.     moveq    #0,d4
  3460. * Exploration loop
  3461. Voo1    btst    d2,d0
  3462.     bne.s    Voo2
  3463. * Stop a voice!
  3464.     btst    d2,d1            * Already stopped?
  3465.     beq.s    VooN
  3466.     bset    d2,d4
  3467.     move.l    d3,(a0)
  3468.     bclr    d2,MuStart+1(a2)
  3469.     bclr    d2,MuStop+1(a2)
  3470.     bra.s    VooN
  3471. * Re start a voice
  3472. Voo2    btst    d2,d1            * Already on?
  3473.     bne.s    VooN
  3474.     bset    d2,MuReStart+1-MB(a3)
  3475. * Next
  3476. VooN    addq.l    #4,a0
  3477.     lea    VoiLong(a1),a1
  3478.     addq.w    #1,d2
  3479.     cmp.w    #4,d2
  3480.     bcs.s    Voo1
  3481. * Stop them!
  3482.     move.l    a2,MuBase-MB(a3)
  3483.     move.w    d4,Circuits+DmaCon
  3484. VooX    movem.l    (sp)+,d0-d5/a0-a3
  3485.     rts
  3486.  
  3487. ******* MUSIC n
  3488. L_IMusic    equ    67
  3489. L67    move.l    (a3)+,d3
  3490.     Rbls    L_IFonc
  3491. * Points to the SONG
  3492.     move.l    a3,-(sp)
  3493.     Dload    a3
  3494.     tst.l    MusBank-MB(a3)
  3495.     Rbeq    L_MnRes
  3496.     move.l    BankSong-MB(a3),a1
  3497.     cmp.w    (a1),d3
  3498.     Rbhi    L_MNDef
  3499.     lsl.w    #2,d3
  3500.     add.l    2-4(a1,d3.w),a1
  3501. * Still room?
  3502.     cmp.w    #3,MuNumber-MB(a3)
  3503.     bcc    IMusX
  3504.     clr.l    MuBase-MB(a3)
  3505. * Buffer address
  3506.     move.w    MuNumber-MB(a3),d0
  3507.     move.w    d0,d1
  3508.     addq.w    #1,MuNumber-MB(a3)
  3509.     mulu    #MuLong,d0
  3510.     lea    MuBuffer-MB(a3),a2
  3511.     add.w    d0,a2
  3512. * Init datas
  3513.     moveq    #(VoiLong*4)/2-1,d0
  3514.     move.l    a2,a0
  3515. IMus1    clr.w    (a0)+
  3516.     dbra    d0,IMus1
  3517.     clr.w    MuStop(a2)
  3518.     clr.w    MuStart(a2)
  3519. * Init parameters
  3520.     move.l    a2,d2
  3521.     move.w    TempoBase-MB(a3),MuCpt(a2)
  3522.     move.w    #17,MuTempo(a2)            *XXX
  3523.     moveq    #0,d0
  3524. IMus2    move.w    #1,VoiCpt(a2)
  3525.     lea    FoEnd-MB(a3),a0
  3526.     move.l    a0,VoiAdr(a2)
  3527.     move.l    a1,a0
  3528.     add.w    0(a0,d0.w),a0
  3529.     move.l    a0,VoiPat(a2)
  3530.     move.l    a0,VoiDPat(a2)
  3531.     lea    NoEffect2(pc),a0
  3532.     move.l    a0,VoiEffect(a2)
  3533.     lea    VoiLong(a2),a2
  3534.     addq.w    #2,d0
  3535.     cmp.w    #8,d0
  3536.     bne.s    IMus2
  3537. * No more samples
  3538.     move.w    #%0000011110000000,Circuits+IntEna
  3539. * Starts music
  3540.     move.l    d2,MuBase-MB(a3)
  3541. IMusX    move.l    (sp)+,a3
  3542.     rts
  3543. NoEffect2
  3544.     move.w    VoiNote(a4),$06(a6)
  3545.     rts
  3546.  
  3547. ******* Tempo T
  3548. L_ITempo    equ    68
  3549. L68    move.l    (a3)+,d0
  3550.     cmp.l    #100,d0
  3551.     Rbhi    L_IFonc
  3552.     Dload    a0
  3553.     move.l    MuBase-MB(a0),d1
  3554.     beq.s    ITemp
  3555.     move.l    d1,a0
  3556.     move.w    d0,MuTempo(a0)
  3557. ITemp    rts
  3558.  
  3559. ***********************************************************
  3560. *    =VU METRE(v)
  3561. L_FVu        equ    69
  3562. L69    move.l    (a3)+,d0
  3563.     cmp.l    #4,d0
  3564.     Rbcc    L_IFonc
  3565.     Dload    a0
  3566.     moveq    #0,d3
  3567.     move.b    0(a0,d0.w),d3
  3568.     clr.b    0(a0,d0.w)
  3569.     moveq    #0,d2
  3570.     rts
  3571.  
  3572. ***********************************************************
  3573. *    =MU BASE
  3574. L_FMB        equ    70
  3575. L70    Dload    a0
  3576.     move.l    a0,d3
  3577.     moveq    #0,d2
  3578.     rts
  3579.  
  3580. ***********************************************************
  3581. *    LED INSTRUCTION
  3582. L_LedOn        equ    71
  3583. L71    bclr    #1,$BFE001
  3584.     rts
  3585. L_LedOf        equ    72
  3586. L72    bset    #1,$BFE001
  3587.     rts
  3588.  
  3589. ***********************************************************
  3590. *    INSTALL THE SAMPLE HANDLER
  3591. L_Sami_install    equ    73
  3592. L73    tst.w    Sami_flag-MB(a3)
  3593.     bne.s    .skip
  3594.     movem.l    d0-d2/a0-a2/a6,-(sp)
  3595.     move.l    $4.w,a6
  3596. ; Save state of interrupts
  3597.     move.w    Circuits+IntEnaR,d0
  3598.     and.w    #%0000011110000000,d0
  3599.     move.w    d0,Sami_OldEna-MB(a3)
  3600.     Rbsr    L_Sami_stop
  3601. ; Install 4 voices
  3602.     lea    Sami_int-MB(a3),a1
  3603.     moveq    #7,d0
  3604. .loop    bsr.s    Sami_start
  3605.     lea    Sami_intl(a1),a1
  3606.     addq.w    #1,d0
  3607.     cmp.w    #11,d0
  3608.     bne.s    .loop
  3609.     subq.w    #1,Sami_flag-MB(a3)
  3610.     movem.l    (sp)+,d0-d2/a0-a2/a6
  3611. .skip    rts
  3612. Sami_start
  3613.     move.l    a1,is_data(a1)
  3614.     move.l    Sami_handad-MB(a3),is_code(a1)
  3615.     move.b    #2,ln_type(a1)
  3616.     move.b    #0,ln_pri(a1)
  3617.     move.l    $4.w,a6    
  3618.     movem.l    d0/a1,-(sp)
  3619.     jsr    -162(a6)        SetIntVector
  3620.     move.l    d0,d1
  3621.     movem.l    (sp)+,d0/a1
  3622.     move.l    d1,Sami_old(a1)
  3623.     rts
  3624.  
  3625. ***********************************************************
  3626. *    REMOVE THE SAMPLE HANDLER
  3627. L_Sami_remove    equ    74
  3628. L74    tst.w    Sami_flag-MB(a3)
  3629.     beq.s    .skip
  3630.     movem.l    a0-a2/a6/d0-d2,-(sp)
  3631.     Rbsr    L_Sami_Stop
  3632.     move.l    $4.w,a6
  3633.     moveq    #7,d2
  3634.     lea    Sami_Int-MB(a3),a2
  3635. .loop    move.l    Sami_old(a2),a1
  3636.     move.l    d2,d0
  3637.     jsr    -162(a6)        SetIntVector
  3638.     lea    Sami_intl(a2),a2
  3639.     addq.w    #1,d2    
  3640.     cmp.w    #11,d2
  3641.     bne.s    .loop
  3642.     lea    Circuits,a0
  3643.     move.w    #$000F,DmaCon(a0)
  3644.     move.w    Sami_oldena-MB(a3),IntEna(a0)
  3645.     clr.w    Sami_flag-MB(a3)
  3646.     movem.l    (sp)+,a0-a2/a6/d0-d2
  3647. .skip    rts
  3648.  
  3649. ***********************************************************
  3650. *    Normal error messages
  3651. ; This routines performs jump to the normal AMOS error messages:
  3652. ; Load in D0 the number of the error, and do a RJmp to L_Error.
  3653. L_IOOMem    equ    75
  3654. L75    
  3655.     moveq    #24,d0
  3656.     Rjmp    L_Error
  3657. L_IFonc        equ    76
  3658. L76    moveq    #23,d0
  3659.     Rjmp    L_Error
  3660.  
  3661. ***********************************************************
  3662. *     Customized error messages
  3663. ; This list of routines just load in D0 the number of the error message in
  3664. ; the extension error-list, and call the error handling routine.
  3665.  
  3666. L_WNDef        equ    77
  3667. L77    moveq    #0,d0    
  3668.     Rbra    L_Custom
  3669. L_SNDef        equ    78
  3670. L78    moveq    #1,d0
  3671.     Rbra    L_Custom
  3672. L_BNSam        equ    79
  3673. L79    moveq    #2,d0
  3674.     Rbra    L_Custom
  3675. L_STSho        equ    80
  3676. L80    moveq    #3,d0
  3677.     Rbra    L_Custom
  3678. L_W0Res        equ    81
  3679. L81    moveq    #4,d0
  3680.     Rbra    L_Custom
  3681. L_MnRes        equ    82
  3682. L82    moveq    #5,d0
  3683.     Rbra    L_Custom
  3684. L_MNDef        equ    83
  3685. L83    moveq    #6,d0
  3686.     Rbra    L_Custom
  3687.  
  3688.  
  3689. ********************************************************************
  3690. *    =SAM SWAPPED(V)
  3691. L_Samswapped    equ    84
  3692. L84    move.l    (a3)+,d0
  3693.     moveq    #0,d2
  3694.     moveq    #0,d3
  3695.     cmp.l    #3,d0
  3696.     Rbhi    L_IFonc
  3697.     move.w    Circuits+IntEnaR,d1
  3698.     lsr.w    #7,d1
  3699.     btst    d0,d1
  3700.     beq.s    .stop
  3701.     Dlea    Sami_int,a0
  3702.     mulu    #Sami_intl,d0
  3703.     tst.l    Sami_radr(a0,d0.l)
  3704.     bne.s    .skip
  3705.     move.l    Sami_pos(a0,d0.l),d1
  3706.     cmp.l    #Sami_lplay,d1
  3707.     beq.s    .skip
  3708.     moveq    #-1,d3
  3709. .skip    rts
  3710. .stop    moveq    #1,d3
  3711.     rts
  3712. *********************************************************************
  3713. *    SAM SWAP
  3714. L_SamSwap    equ    85
  3715. L85    move.l    (a3)+,d4
  3716.     Rbmi    L_IFonc
  3717.     move.l    (a3)+,d0
  3718.     Rjsr    L_Bnk.OrAdr
  3719.     move.l    d0,d3
  3720.     move.l    (a3)+,d2
  3721.     moveq    #0,d1
  3722.     Dlea    Sami_int,a0
  3723. .loop    btst    d1,d2
  3724.     beq.s    .skip
  3725.     move.l    d3,Sami_radr(a0)
  3726.     move.l    d4,Sami_rlong(a0)
  3727. .skip    lea    Sami_intl(a0),a0
  3728.     addq.w    #1,d1
  3729.     cmp.w    #4,d1
  3730.     bne.s    .loop
  3731.     rts
  3732. *********************************************************************
  3733. *    SAM STOP
  3734. L_SamStop0    equ    86
  3735. L86    move.l    #$f,-(a3)
  3736.     RBra    L_SamStop1
  3737. L_SamStop1    equ    87
  3738. L87    move.l    (a3)+,d1
  3739.     and.l    #$F,d1
  3740.     move.w    d1,Circuits+DmaCon
  3741.     lsl.w    #7,d1    
  3742.     move.w    d1,Circuits+IntEna
  3743.     rts
  3744.  
  3745. *********************************************************************
  3746. *    TRACKER instructions
  3747.  
  3748. *******    TRACK LOAD "nom",banque
  3749. L_Trackload    equ    88
  3750. L88    
  3751.     move.l    (a3)+,d3
  3752.     cmp.l    #$10000,d3
  3753.     Rbge    L_IFonc
  3754.     Dload    a0
  3755.     cmp.w    Track_Bank-MB(a0),d3
  3756.     bne.s    .kkk
  3757.     tst.b    mt_on-MB(a0)
  3758.     beq.s    .kkk
  3759.     RBsr    L_TrackStop
  3760. .kkk    move.w    d3,Track_Bank-MB(a0)    * Numero de la banque
  3761.     move.l    d3,-(sp)
  3762. ; Get name to load
  3763. ; ~~~~~~~~~~~~~~~~
  3764.     move.l    (a3)+,a0
  3765.     move.w    (a0)+,d0
  3766.     subq.w    #1,d0    
  3767.     cmp.w    #128,d0
  3768.     Rbcc    L_IFonc
  3769.     move.l    Name1(a5),a1
  3770. .loop    move.b    (a0)+,(a1)+
  3771.     dbra    d0,.loop
  3772.     clr.b    (a1)
  3773.     Rjsr    L_Dsk.PathIt
  3774. ; Open the file
  3775. ; ~~~~~~~~~~~~~
  3776.     move.l    Name1(a5),d1
  3777.     move.l    #1005,d2
  3778.     move.l    a6,-(sp)
  3779.     move.l    DosBase(a5),a6
  3780.     jsr    -30(a6)            DosOpen, fichier sons
  3781.     move.l    (sp)+,a6
  3782.     move.l    d0,d7
  3783.     Rbeq    L_IDError
  3784.     move.l    d7,d1            Trouve la taille
  3785.     bsr    .taille
  3786.     move.l    d0,d6
  3787. ; Reserve the bank
  3788. ; ~~~~~~~~~~~~~~~~
  3789.     move.l    (sp)+,d0                Numero
  3790.     moveq    #(1<<Bnk_BitData+1<<Bnk_BitChip),d1    Flag
  3791.     move.l    d6,d2                    Taille
  3792.     lea    BkTrack(pc),a0                Nom
  3793.     Rjsr    L_Bnk.Reserve
  3794.     beq    .mem
  3795. ; Load the music
  3796. ; ~~~~~~~~~~~~~~
  3797.     move.l    d7,d1
  3798.     move.l    a0,d2
  3799.     move.l    d6,d3
  3800.     move.l    a6,-(sp)
  3801.     move.l    DosBase(a5),a6
  3802.     jsr    -42(a6)            Read
  3803.     move.l    (sp)+,a6
  3804.     move.l    d0,d2
  3805.     move.l    d7,d1
  3806.     bsr    .clo
  3807.     cmp.l    d2,d3
  3808.     Rbne    L_IFonc
  3809.     rts
  3810. * Close the file
  3811. .clo    movem.l    a6/a0/a1,-(sp)
  3812.     move.l    DosBase(a5),a6
  3813.     jsr    -36(a6)            Close
  3814.     movem.l    (sp)+,a6/a0/a1
  3815.     rts
  3816. * Out of memory
  3817. .mem    move.l    d7,d1
  3818.     bsr.s    .clo
  3819.     RBra    L_IOOMem
  3820. * Find the size of the file
  3821. .taille    move.l    a6,-(sp)
  3822.     move.l    d1,-(sp)
  3823.     moveq    #0,d2
  3824.     moveq    #1,d3
  3825.     move.l    DosBase(a5),a6
  3826.     jsr    -66(a6)            DosSeek
  3827.     move.l    (sp)+,d1
  3828.     move.l    d0,d2
  3829.     moveq    #-1,d3
  3830.     move.l    DosBase(a5),a6
  3831.     jsr    -66(a6)            DosSeek
  3832.     move.l    (sp)+,a6
  3833.     rts
  3834. BkTrack    dc.b    "Tracker "
  3835.     even
  3836.  
  3837. ******* TRACK CHECK, arrete la musique si pas banque...
  3838. L_TrackCheck    equ    89
  3839. L89    movem.l    a0-a1,-(sp)
  3840.     DLoad    a1
  3841.     tst.b    mt_on-MB(a1)
  3842.     beq.s    .skip
  3843.     move.l    mt_data-MB(a1),a0
  3844.     cmp.l    #"ker ",-(a0)
  3845.     bne.s    .stop
  3846.     cmp.l    #"Trac",-(a0)
  3847.     beq.s    .skip
  3848. .stop    RBsr    L_TrackStop
  3849. .skip    movem.l    (sp)+,a0-a1
  3850.     rts
  3851.  
  3852. ******* TRACK STOP
  3853. L_TrackStop    equ    90
  3854. L90    move.l    a0,-(sp)
  3855.     Dload    a0
  3856.     tst.b    mt_on-MB(a0)
  3857.     beq.s    .Skip
  3858.     clr.b    mt_on-MB(a0)
  3859.     moveq    #0,d0
  3860.     lea    $dff000,a0
  3861.     move.w    d0,$a8(a0)
  3862.     move.w    d0,$b8(a0)
  3863.     move.w    d0,$c8(a0)
  3864.     move.w    d0,$d8(a0)
  3865.     move.w    #$f,$dff096
  3866. .Skip    move.l    (sp)+,a0
  3867.     rts
  3868.  
  3869. ******* TRACK LOOP ON/OFF
  3870. L_TrackLoopon    equ    91
  3871. L91    rts
  3872. L_TrackLoopof    equ    92
  3873. L92    rts
  3874.  
  3875. ******* TRACK PLAY [Bank],[Pattern]
  3876.  
  3877. L_TrackPlay0    equ    93
  3878. L93
  3879.     move.l    #Entnul,-(a3)
  3880.     Rbra    94
  3881.  
  3882. L_TrackPlay1    equ    94
  3883. L94    
  3884.     move.l    #Entnul,-(a3)
  3885.     Rbra    95
  3886.  
  3887. L_TrackPlay2    equ    95
  3888. L95    
  3889.     move.l    (a3)+,d7
  3890.     cmp.l    #Entnul,(a3)
  3891.     bne.s    .skip
  3892.     Dload    a0
  3893.     moveq    #0,d0
  3894.     move.w    Track_Bank-MB(a0),d0
  3895.     move.l    d0,(a3)
  3896. .skip    
  3897.     move.l    (a3)+,d0
  3898.     Rjsr    L_Bnk.OrAdr
  3899.     move.l    d0,a2
  3900.     cmp.l    #"Trac",-8(a2)    
  3901.     bne    .nobank
  3902.     cmp.l    #"ker ",-4(a2)
  3903.     bne    .nobank
  3904.     
  3905.     Rbsr    L_SamStop0
  3906.     Rbsr    L_TrackStop
  3907.     
  3908. ; Init music...
  3909. ; ~~~~~~~~~~~~~
  3910.     move.l    a3,-(sp)
  3911.     Dload    a3
  3912.     move.l    a2,a0
  3913.     move.l    a0,mt_data-MB(a3)
  3914.     lea    mt_mulu-MB(a3),a1
  3915.     moveq    #$0c,d0
  3916.     add.l    a0,d0
  3917.     moveq    #$1f,d1
  3918.     moveq    #$1e,d3
  3919. .lop4    move.l    d0,(a1)+
  3920.     add.l    d3,d0
  3921.     dbf    d1,.lop4
  3922.  
  3923.     lea    $3b8(a0),a1
  3924.     moveq    #$7f,d0
  3925.     moveq    #0,d1
  3926.     moveq    #0,d2
  3927. .lop2    move.b    (a1)+,d1
  3928.     cmp.b    d2,d1
  3929.     ble.s    .lop
  3930.     move.l    d1,d2
  3931. .lop    dbf    d0,.lop2
  3932.     addq.w    #1,d2
  3933.  
  3934.     asl.l    #8,d2
  3935.     asl.l    #2,d2
  3936.     lea    4(a1,d2.l),a2
  3937.     lea    mt_samplestarts-MB(a3),a1
  3938.     add.w    #$2a,a0
  3939.     moveq    #$1e,d0
  3940. .lop3    clr.l    (a2)
  3941.     move.l    a2,(a1)+
  3942.     moveq    #0,d1
  3943.     move.b    d1,2(a0)
  3944.     move.w    (a0),d1
  3945.     asl.l    #1,d1
  3946.     add.l    d1,a2
  3947.     add.l    d3,a0
  3948.     dbf    d0,.lop3
  3949.  
  3950.     move.b    #6,mt_speed-mt_samplestarts-$7c(a1)
  3951.     moveq    #0,d0
  3952.     lea    $dff000,a0
  3953.     move.w    d0,$a8(a0)
  3954.     move.w    d0,$b8(a0)
  3955.     move.w    d0,$c8(a0)
  3956.     move.w    d0,$d8(a0)
  3957.     move.b    d0,mt_songpos-mt_samplestarts-$7c(a1)
  3958.     move.b    d0,mt_counter-mt_samplestarts-$7c(a1)
  3959.     move.w    d0,mt_pattpos-mt_samplestarts-$7c(a1)
  3960.  
  3961. ; Demarage de la musique!
  3962. ; ~~~~~~~~~~~~~~~~~~~~~~~
  3963.     move.b    #1,mt_on-MB(a3)
  3964.     move.l    (sp)+,a3    
  3965.     rts
  3966. * Pas un module tracker
  3967. .nobank    moveq    #8,d0
  3968.     Rbra    L_Custom
  3969.  
  3970. ******* Erreur disque
  3971. L_IDError    equ    96
  3972. L96    move.w    #DEBase+15,d0
  3973.     Rjmp    L_Error
  3974.  
  3975. ******* Routine, demande la bouche du narrator
  3976. L_Lips        equ    97
  3977. L97    Dload    a2
  3978.     tst.l    TranBase-MB(a2)
  3979.     beq.s    .Err
  3980.     move.l    WriteIo-MB(a2),d0
  3981.     beq.s    .Err
  3982.     move.l    d0,a0
  3983.     tst.b    66(a0)
  3984.     beq.s    .Err
  3985.     lea    ReadIo-MB(a2),a1
  3986.     move.w    #2,28(a1)            CMD_READ
  3987.     move.l    a6,-(sp)
  3988.     move.l    $4.w,a6
  3989.     jsr    DoIO(a6)
  3990.     move.l    (sp)+,a6
  3991.     lea    ReadIo-MB(a2),a1
  3992.     cmp.b    #-8,$1f(a1)            ND_NOWRITE
  3993.     beq.s    .Err
  3994.     rts
  3995. .Err    lea    ReadIo-MB(a2),a0
  3996.     move.w    #-1,88(a0)
  3997.     rts
  3998.  
  3999. *********************************************************************
  4000. *    AMIGA.LIB linked code. 
  4001. *    In order to make it relocatable, I have been
  4002. *    obliged to disassemble the code and include it in this 
  4003. *    routine.
  4004. L_Amiga.Lib    equ    98
  4005. L98    lsl.w    #2,d0
  4006.     lea    JJJmp(pc),a0
  4007.     jmp    0(a0,d0.w)
  4008. JJJmp    bra    _CreatePort
  4009.     bra    _DeletePort
  4010.     bra    _CreateExtIO
  4011.     bra    _DeleteExtIO
  4012.  
  4013. _CreatePort
  4014.     MOVEM.L    D2-7/A2,-(A7)
  4015.     MOVE.L    $20(A7),D4
  4016.     MOVE.B    $27(A7),D3
  4017.     MOVE.L    #$FFFFFFFF,-(A7)
  4018.     BSR    L7C7DB14
  4019.     MOVE.L    D0,D5
  4020.     MOVE.L    D5,D6
  4021.     MOVEQ    #-1,D2
  4022.     CMP.L    D5,D2
  4023.     ADDQ.L    #4,A7
  4024.     BNE.S    L7C7D97A
  4025.     MOVEQ    #0,D0
  4026.     BRA    L7C7D9E6
  4027. L7C7D97A    MOVE.L    #$10001,-(A7)
  4028.     PEA    $22.W
  4029.     BSR    L7C7DAD0
  4030.     MOVEA.L    D0,A2
  4031.     EXG    D7,A2
  4032.     TST.L    D7
  4033.     EXG    D7,A2
  4034.     ADDQ.L    #8,A7
  4035.     BNE.S    L7C7D9A4
  4036.     MOVE.L    D6,-(A7)
  4037.     BSR    L7C7DB28
  4038.     MOVEQ    #0,D0
  4039.     ADDQ.L    #4,A7
  4040.     BRA.S    L7C7D9E6
  4041. L7C7D9A4    MOVE.L    D4,$A(A2)
  4042.     MOVE.B    D3,9(A2)
  4043.     MOVE.B    #4,8(A2)
  4044.     CLR.B    $E(A2)
  4045.     MOVE.B    D6,$F(A2)
  4046.     CLR.L    -(A7)
  4047.     BSR    L7C7DB00
  4048.     MOVE.L    D0,$10(A2)
  4049.     TST.L    D4
  4050.     ADDQ.L    #4,A7
  4051.     BEQ.S    L7C7D9D8
  4052.     MOVE.L    A2,-(A7)
  4053.     BSR    L7C7DB3C
  4054.     ADDQ.L    #4,A7
  4055.     BRA.S    L7C7D9E4
  4056. L7C7D9D8    PEA    $14(A2)
  4057.     BSR    _NewList
  4058.     ADDQ.L    #4,A7
  4059. L7C7D9E4    MOVE.L    A2,D0
  4060. L7C7D9E6    MOVEM.L    (A7)+,D2-7/A2
  4061.     RTS
  4062.  
  4063. _DeletePort
  4064.     MOVEM.L    D2/A2,-(A7)
  4065.     MOVEA.L    $C(A7),A2
  4066.     TST.L    $A(A2)
  4067.     BEQ.S    L7C7DA04
  4068.     MOVE.L    A2,-(A7)
  4069.     BSR    L7C7DB50
  4070.     ADDQ.L    #4,A7
  4071. L7C7DA04    MOVE.B    #$FF,8(A2)
  4072.     MOVEQ    #-1,D2
  4073.     MOVE.L    D2,$14(A2)
  4074.     MOVEQ    #0,D2
  4075.     MOVE.B    $F(A2),D2
  4076.     MOVE.L    D2,-(A7)
  4077.     BSR    L7C7DB28
  4078.     PEA    $22.W
  4079.     MOVE.L    A2,-(A7)
  4080.     BSR    L7C7DAE8
  4081.     LEA    $C(A7),A7
  4082.     MOVEM.L    (A7)+,D2/A2
  4083.     RTS
  4084. _CreateExtIO
  4085.     MOVEM.L    D2-4,-(A7)
  4086.     MOVE.L    $10(A7),D2
  4087.     MOVE.L    $14(A7),D3
  4088.     TST.L    D2
  4089.     BNE.S    L7C7DA54
  4090.     MOVEQ    #0,D0
  4091.     BRA.S    L7C7DA82
  4092. L7C7DA54    MOVE.L    #$10001,-(A7)
  4093.     MOVE.L    D3,-(A7)
  4094.     BSR    L7C7DAD0
  4095.     MOVEA.L    D0,A0
  4096.     EXG    D4,A0
  4097.     TST.L    D4
  4098.     EXG    D4,A0
  4099.     ADDQ.L    #8,A7
  4100.     BNE.S    L7C7DA72
  4101.     MOVEQ    #0,D0
  4102.     BRA.S    L7C7DA82
  4103. L7C7DA72    MOVE.B    #5,8(A0)
  4104.     MOVE.W    D3,$12(A0)
  4105.     MOVE.L    D2,$E(A0)
  4106.     MOVE.L    A0,D0
  4107. L7C7DA82    MOVEM.L    (A7)+,D2-4
  4108.     RTS
  4109.  
  4110. _DeleteExtIO
  4111.     MOVEM.L    D2-3,-(A7)
  4112.     MOVEA.L    $C(A7),A0
  4113.     EXG    D3,A0
  4114.     TST.L    D3
  4115.     EXG    D3,A0
  4116.     BEQ    L7C7DABE
  4117.     MOVE.B    #$FF,8(A0)
  4118.     MOVEQ    #-1,D2
  4119.     MOVE.L    D2,$14(A0)
  4120.     MOVEQ    #-1,D2
  4121.     MOVE.L    D2,$18(A0)
  4122.     MOVEQ    #0,D2
  4123.     MOVE.W    $12(A0),D2
  4124.     MOVE.L    D2,-(A7)
  4125.     MOVE.L    A0,-(A7)
  4126.     BSR    L7C7DAE8
  4127.     ADDQ.L    #8,A7
  4128. L7C7DABE    MOVEM.L    (A7)+,D2-3
  4129.     RTS
  4130. L7C7DAD0
  4131.     MOVE.L    A6,-(A7)
  4132.     MOVEA.L    $4.w,A6
  4133.     MOVEM.L    8(A7),D0-1
  4134.     JSR    -$C6(A6)
  4135.     MOVEA.L    (A7)+,A6
  4136.     RTS
  4137. L7C7DAE8
  4138.     MOVE.L    A6,-(A7)
  4139.     MOVEA.L    $4.w,A6
  4140.     MOVEA.L    8(A7),A1
  4141.     MOVE.L    $C(A7),D0
  4142.     JSR    -$D2(A6)
  4143.     MOVEA.L    (A7)+,A6
  4144.     RTS
  4145. L7C7DB00
  4146.     MOVE.L    A6,-(A7)
  4147.     MOVEA.L    $4.w,A6
  4148.     MOVEA.L    8(A7),A1
  4149.     JSR    -$126(A6)
  4150.     MOVEA.L    (A7)+,A6
  4151.     RTS
  4152. L7C7DB14
  4153.     MOVE.L    A6,-(A7)
  4154.     MOVEA.L    $4.w,A6
  4155.     MOVE.L    8(A7),D0
  4156.     JSR    -$14A(A6)
  4157.     MOVEA.L    (A7)+,A6
  4158.     RTS
  4159. L7C7DB28
  4160.     MOVE.L    A6,-(A7)
  4161.     MOVEA.L    $4.w,A6
  4162.     MOVE.L    8(A7),D0
  4163.     JSR    -$150(A6)
  4164.     MOVEA.L    (A7)+,A6
  4165.     RTS
  4166. L7C7DB3C
  4167.     MOVE.L    A6,-(A7)
  4168.     MOVEA.L    $4.w,A6
  4169.     MOVEA.L    8(A7),A1
  4170.     JSR    -$162(A6)
  4171.     MOVEA.L    (A7)+,A6
  4172.     RTS
  4173. L7C7DB50
  4174.     MOVE.L    A6,-(A7)
  4175.     MOVEA.L    $4.w,A6
  4176.     MOVEA.L    8(A7),A1
  4177.     JSR    -$168(A6)
  4178.     MOVEA.L    (A7)+,A6
  4179.     RTS
  4180. _NewList
  4181.     move.l    4(a7),a0
  4182.     move.l    a0,(a0)
  4183.     addq.l    #4,(a0)
  4184.     clr.l    4(a0)
  4185.     move.l    a0,8(a0)
  4186.     rts
  4187.  
  4188. ******* TALK MISC volume,freq
  4189. L_TalkMisc        equ    99
  4190. L99    Rbsr    L_OpNar
  4191.     move.l    #EntNul,d0
  4192.     Dload    a1
  4193.     move.l    WriteIo-MB(a1),a1
  4194.     move.l    (a3)+,d1
  4195.     cmp.l    d0,d1
  4196.     beq.s    .IRd0
  4197.     cmp.w    #5000,d1
  4198.     Rbcs    L_IFonc
  4199.     cmp.w    #25000,d1
  4200.     Rbhi    L_IFonc
  4201.     move.w    d1,64(a1)
  4202. .IRd0
  4203.     move.l    (a3)+,d1
  4204.     cmp.l    d0,d1
  4205.     beq.s    .IRd1
  4206.     tst.l    d1
  4207.     RBmi    L_IFonc
  4208.     cmp.w    #64,d1
  4209.     Rbhi    L_IFonc
  4210.     move.w    d1,62(a1)
  4211. .IRd1
  4212.     rts
  4213.  
  4214. *********************************************************************
  4215. *    SSAVE fichier,adresse To fin
  4216. L_SSave        equ    100
  4217. L100    move.l    (a3)+,d3        End adress
  4218.     move.l    (a3)+,d2        Start Adress
  4219.     sub.l    d2,d3
  4220.     RBle    L_IFonc
  4221.     move.l    (a3)+,d0        File
  4222.     cmp.l    #10,d0
  4223.     Rbcc    L_IFonc
  4224.     subq.l    #1,d0
  4225.     Rbmi    L_IFonc
  4226.     mulu    #TFiche,d0
  4227.     lea    Fichiers(a5),a2
  4228.     add.w    d0,a2
  4229.     move.l    Fha(a2),d1
  4230.     Rbeq    L_IFonc
  4231.     btst    #2,FhT(a2)
  4232.     Rbne    L_IFonc
  4233. * Save the data
  4234.     move.l    a6,-(sp)
  4235.     move.l    DosBase(a5),a6
  4236.     jsr    _LVOWrite(a6)
  4237.     move.l    (sp)+,a6
  4238.     tst.l    d0
  4239.     RBmi    L_IDError
  4240.     rts
  4241.  
  4242.  
  4243. ; ___________________________________________________________________
  4244. ;
  4245. ;    MED instructions
  4246. ; ___________________________________________________________________
  4247.  
  4248. ;    MED LOAD "nom",banque
  4249. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4250. L_MedLoad    equ    101
  4251. L101    Rbsr    L_MedOpen
  4252.     move.l    (a3)+,d3
  4253.     cmp.l    #$10000,d3
  4254.     Rbge    L_IFonc
  4255.     Dload    a2
  4256.     cmp.w    Med_Bank-MB(a2),d3
  4257.     bne.s    .k
  4258.     Rbsr    L_MedStop
  4259. .k    move.w    d3,Med_Bank-MB(a2)    * Numero de la banque
  4260. ; Get name to load
  4261. ; ~~~~~~~~~~~~~~~~
  4262.     move.l    (a3)+,a0
  4263.     move.w    (a0)+,d0
  4264.     subq.w    #1,d0    
  4265.     cmp.w    #128,d0
  4266.     Rbcc    L_IFonc
  4267.     move.l    Name1(a5),a1
  4268. .loop    move.b    (a0)+,(a1)+
  4269.     dbra    d0,.loop
  4270.     clr.b    (a1)
  4271.     Rjsr    L_Dsk.PathIt
  4272. ; Trouve la taille
  4273. ; ~~~~~~~~~~~~~~~~
  4274.     move.l    Name1(a5),d1
  4275.     move.l    #1005,d2
  4276.     move.l    a6,-(sp)
  4277.     move.l    DosBase(a5),a6
  4278.     jsr    -30(a6)            DosOpen,
  4279.     move.l    (sp)+,a6
  4280.     move.l    d0,d7
  4281.     Rbeq    L_IDError
  4282.     move.l    d7,d1            Trouve la taille
  4283.     bsr    .taille
  4284.     move.l    d0,d6
  4285. ; Reserve la banque
  4286. ; ~~~~~~~~~~~~~~~~~
  4287.     move.w    Med_Bank-MB(a2),d0            Numero de la banque
  4288.     ext.l    d0
  4289.     moveq    #(1<<Bnk_BitChip),d1            Flag CHIP
  4290.     move.l    d6,d2
  4291.     addq.l    #8,d2                    Taille
  4292.     lea    .BkMed(pc),a0                Nom
  4293.     Rjsr    L_Bnk.Reserve
  4294.     beq    .mem
  4295.     move.l    a0,a2
  4296. ; Charge la musique
  4297. ; ~~~~~~~~~~~~~~~~~
  4298.     move.l    d7,d1
  4299.     move.l    a2,d2
  4300.     move.l    d6,d3
  4301.     move.l    a6,-(sp)
  4302.     move.l    DosBase(a5),a6
  4303.     jsr    -42(a6)            Read
  4304.     move.l    (sp)+,a6
  4305.     move.l    d0,d2
  4306.     move.l    d7,d1
  4307.     bsr    .clo
  4308.     cmp.l    d2,d3
  4309.     Rbne    L_IFonc
  4310.     cmp.l    #"MMD0",(a2)
  4311.     beq.s    .ok
  4312.     cmp.l    #"MMD1",(a2)
  4313.     bne.s    .med
  4314. ; Relocation du module
  4315. ; ~~~~~~~~~~~~~~~~~~~~
  4316. .ok    move.l    a6,-(sp)
  4317.     Dload    a0
  4318.     move.l    Med_Base-MB(a0),a6
  4319.     move.l    a2,a0
  4320.     jsr    _MEDRelocModule(a6)
  4321.     move.l    (sp)+,a6
  4322.     rts
  4323. * Ferme le fichier
  4324. .clo    movem.l    a6/a0/a1,-(sp)
  4325.     move.l    DosBase(a5),a6
  4326.     jsr    -36(a6)            Close
  4327.     movem.l    (sp)+,a6/a0/a1
  4328.     rts
  4329. * Out of memory
  4330. .mem    move.l    d7,d1
  4331.     beq.s    .xx
  4332.     bsr.s    .clo
  4333. .xx    Rbra    L_IOOMem
  4334. * Not a MED file
  4335. .med    Dlea    Med_Bank,a0
  4336.     move.w    (a0),d0
  4337.     ext.l    d0
  4338.     Rjsr    L_Bnk.Eff
  4339.     move.w    #189,d0
  4340.     Rjmp    L_Error
  4341. * Routine, trouve la taille d'un fichier
  4342. .taille    move.l    a6,-(sp)
  4343.     move.l    d1,-(sp)
  4344.     moveq    #0,d2
  4345.     moveq    #1,d3
  4346.     move.l    DosBase(a5),a6
  4347.     jsr    -66(a6)            DosSeek
  4348.     move.l    (sp)+,d1
  4349.     move.l    d0,d2
  4350.     moveq    #-1,d3
  4351.     move.l    DosBase(a5),a6
  4352.     jsr    -66(a6)            DosSeek
  4353.     move.l    (sp)+,a6
  4354.     rts
  4355. .BkMed    dc.b    "Med     "
  4356.     even
  4357.  
  4358. ;    MED CHECK, arrete la musique si pas banque...
  4359. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4360. L_MedCheck    equ    102
  4361. L102    movem.l    d0/a0-a1,-(sp)
  4362.     DLoad    a1
  4363.     tst.b    Med_On-MB(a1)
  4364.     beq.s    .skip
  4365.     move.l    Med_Adr-MB(a1),d0
  4366.     beq.s    .skip
  4367.     move.l    d0,a0
  4368.     cmp.l    #"Med ",-(a0)
  4369.     bne.s    .stop
  4370.     cmp.l    #"    ",-(a0)
  4371.     beq.s    .skip
  4372. .stop    Rbsr    L_MedStop
  4373.     clr.l    Med_Adr-MB(a1)
  4374. .skip    movem.l    (sp)+,d0/a0-a1
  4375.     rts
  4376.  
  4377. ;    MED STOP
  4378. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4379. L_MedStop    equ    103
  4380. L103    movem.l    a0-a2/a6/d0-d2,-(sp)
  4381.     Dload    a0
  4382.     tst.b    Med_On-MB(a0)
  4383.     beq.s    .NoMed
  4384.     clr.b    Med_On-MB(a0)
  4385.     move.l    Med_Base-MB(a0),a6
  4386.     jsr    _MEDStopPlayer(a6)
  4387. .NoMed    movem.l    (sp)+,a0-a2/a6/d0-d2
  4388.     rts
  4389.  
  4390. ;    MED PLAY [Bank],[Song]
  4391. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4392. L_MedPlay0    equ    104
  4393. L104    move.l    #EntNul,-(a3)
  4394.     Rbra    L_MedPlay1
  4395. L_MedPlay1    equ    105
  4396. L105    move.l    #EntNul,-(a3)
  4397.     Rbra    L_MedPlay2
  4398. L_MedPlay2    equ    106
  4399. L106    Dload    a2            Arret d'une eventuelle musique
  4400.     Rbsr    L_MedOpen        Ouvre la librairie, s'il faut
  4401.     Rbsr    L_MedStop
  4402.     clr.l    Med_Adr-MB(a2)
  4403. ; Verification de la banque
  4404. ; ~~~~~~~~~~~~~~~~~~~~~~~~~
  4405.     move.l    (a3)+,d7
  4406.     cmp.l    #Entnul,(a3)
  4407.     bne.s    .skip
  4408.     moveq    #0,d0
  4409.     move.w    Med_Bank-MB(a2),d0
  4410.     move.l    d0,(a3)
  4411. .skip    move.l    (a3)+,d0
  4412.     Rjsr    L_Bnk.OrAdr
  4413.     move.l    d0,a2
  4414.     cmp.l    #"Med ",-8(a2)    
  4415.     bne    .nobank
  4416.     cmp.l    #"    ",-4(a2)
  4417.     bne    .nobank
  4418.     
  4419. ; Arret de tous les sons...
  4420. ; ~~~~~~~~~~~~~~~~~~~~~~~~~
  4421.     Rbsr    L_SamStop0
  4422.     Rbsr    L_TrackStop
  4423.     Rbsr    L_MedStop
  4424. ; Pointe la chanson
  4425. ; ~~~~~~~~~~~~~~~~~
  4426.     movem.l    a3/a6,-(sp)
  4427.     Dload    a3
  4428.     moveq    #0,d0
  4429.     cmp.l    #Entnul,d7
  4430.     beq.s    .skp
  4431.     move.l    d7,d0
  4432. .skp    move.l    Med_Base-MB(a3),a6
  4433.     jsr    _MEDSetModnum(a6)
  4434. ; Demarre la chanson
  4435. ; ~~~~~~~~~~~~~~~~~~
  4436.     move.l    a2,a0
  4437.     jsr    _MEDPlayModule(a6)
  4438.     move.l    a2,Med_Adr-MB(a3)
  4439.     move.b    #1,Med_On-MB(a3)
  4440. ; Terminé
  4441. ; ~~~~~~~
  4442.     movem.l    (sp)+,a3/a6
  4443.     rts
  4444. ; Pas une banque MED
  4445. ; ~~~~~~~~~~~~~~~~~~
  4446. .nobank    moveq    #8,d0
  4447.     Rbra    L_Custom
  4448.  
  4449. ;     Ouvre la librairie MED
  4450. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4451. L_MedOpen    equ    107
  4452. L107    movem.l    a0-a2/d0-d2,-(sp)
  4453.     Dload    a2
  4454.     tst.l    Med_Base-MB(a2)
  4455.     bne.s    .Open
  4456.     lea    Med_Name-MB(a2),a1
  4457.     moveq    #2,d0            2 et pas 3!!!!!!!!!!!!!!!!!!!!
  4458.     move.l    a6,-(sp)
  4459.     move.l    $4.w,a6
  4460.     jsr    _LVOOpenLibrary(a6)
  4461.     move.l    (sp)+,a6
  4462.     move.l    d0,Med_Base-MB(a2)
  4463.     beq.s    .Err1
  4464.     moveq    #0,d0
  4465.     move.b    Med_Midi-MB(a2),d0
  4466.     move.l    a6,-(sp)
  4467.     move.l    Med_Base-MB(a2),a6
  4468.     jsr    _MEDGetPlayer(a6)
  4469.     move.l    (sp)+,a6
  4470.     tst.l    d0
  4471.     bne    .Err2
  4472. .Open    movem.l    (sp)+,a0-a2/d0-d2
  4473.     rts
  4474. .Err1    move.w    #187,d0            Cannot load med.lib
  4475.     Rjmp    L_Error
  4476. .Err2    Rbsr    L_MedClose        Cannot initialise med.lib
  4477.     move.w    #188,d0
  4478.     Rjmp    L_Error    
  4479.  
  4480. ;    MED MIDI ON / OFF
  4481. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4482. L_MedMidiOn    equ    108    
  4483. L108    Dlea    Med_Midi,a0
  4484.     move.b    #1,(a0)
  4485.     rts
  4486. L109
  4487.  
  4488. ;    MED CLOSE
  4489. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4490. L_MedClose    equ    110
  4491. L110    movem.l    a0-a2/a6/d0-d2,-(sp)
  4492.     Rbsr    L_MedStop
  4493.     Dload    a2
  4494.     clr.b    Med_Midi-MB(a2)
  4495.     clr.l    Med_Adr-MB(a2)
  4496.     move.l    Med_Base-MB(a2),d0
  4497.     beq.s    .Skip
  4498.     move.l    d0,a6
  4499.     jsr    _MEDFreePlayer(a6)
  4500.     move.l    Med_Base-MB(a2),a1
  4501.     clr.l    Med_Base-MB(a2)
  4502.     move.l    $4.w,a6
  4503.     jsr    _LVOCloseLibrary(a6)
  4504. .Skip    movem.l    (sp)+,a0-a2/a6/d0-d2
  4505.     rts
  4506.  
  4507. ;    MED CONT
  4508. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4509. L_MedCont    equ    111
  4510. L111    movem.l    a0-a2/a6/d0-d2,-(sp)
  4511.     Dload    a0
  4512.     move.l    Med_Adr-MB(a0),d0
  4513.     beq.s    .Skip
  4514.     tst.b    Med_On-MB(a0)
  4515.     bne.s    .Skip
  4516.     move.b    #1,Med_On-MB(a0)
  4517.     move.l    Med_Base-MB(a0),a6
  4518.     move.l    d0,a0
  4519.     jsr    _MEDContModule(a6)
  4520. .Skip    movem.l    (sp)+,a0-a2/a6/d0-d2
  4521.     rts
  4522.     
  4523.  
  4524. *********************************************************************
  4525. *    ERROR MESSAGES...
  4526. ;
  4527. ; You know that the compiler have a -E1 option (with errors) and a 
  4528. ; a -E0 (without errors). To achieve that, the compiler copies one of
  4529. ; the two next routines, depending on the -E flag. If errors are to be
  4530. ; copied along with the program, then the next next routine is used. If not,
  4531. ; then the next one is copied.
  4532. ; The compiler assumes that the two last routines in the library handles
  4533. ; the errors: the previous last is WITH errors, the last is WITHOUT. So,
  4534. ; remember:
  4535. ;
  4536. ; THESE ROUTINES MUST BE THE LAST ONES IN THE LIBRARY
  4537. ;
  4538. ; The AMOS interpretor always needs errors. So make all your custom errors
  4539. ; calls point to the L_Custom routine, and everything will work fine...
  4540. ;
  4541. ******* "With messages" routine.
  4542. ; The following routine is the one your program must call to output
  4543. ; a extension error message. It will be used under interpretor and under
  4544. ; compiled program with -E1
  4545.  
  4546. L_Custom    equ    112
  4547. L112    lea    ErrMess(pc),a0
  4548.     moveq    #0,d1            * Can be trapped
  4549.     moveq    #ExtNb,d2        * Number of extension
  4550.     moveq    #0,d3            * IMPORTANT!!!
  4551.     RJmp    L_ErrorExt        * Jump to routine...
  4552. * Messages...
  4553. ErrMess    dc.b    "Wave not defined",0            *0
  4554.     dc.b     "Sample not defined",0            *1
  4555.     dc.b     "Sample bank not found",0        *2
  4556.     dc.b    "256 characters for a wave",0        *3
  4557.     dc.b    "Wave 0 and 1 are reserved",0        *4
  4558.     dc.b    "Music bank not found",0        *5
  4559.     dc.b     "Music not defined",0            *6
  4560.     dc.b    "Can't open narrator",0            *7
  4561.     dc.b    "Not a tracker module",0        *8
  4562. * IMPORTANT! Always EVEN!
  4563.     even
  4564.  
  4565. ******* "No errors" routine
  4566. ; If you compile with -E0, the compiler will replace the previous
  4567. ; routine by this one. This one just sets D3 to -1, and does not
  4568. ; load messages in A0. Anyway, values in D1 and D2 must be valid.
  4569. ;    
  4570. ; THIS ROUTINE MUST BE THE LAST ONE IN THE LIBRARY!
  4571. ;
  4572.  
  4573. L113    moveq    #0,d1
  4574.     moveq    #ExtNb,d2
  4575.     moveq    #-1,d3
  4576.     RJmp    L_ErrorExt
  4577.  
  4578. ; Do not forget the last label to delimit the last library routine!
  4579. L114
  4580.  
  4581. ; ---------------------------------------------------------------------
  4582. ; Now the title of the extension, just the string.
  4583. ;
  4584. ; TITLE MESSAGE
  4585. C_Title    dc.b    "AMOSPro Music extension V "
  4586.     Version
  4587.     dc.b    0,"$VER: "
  4588.     Version
  4589.     dc.b    0
  4590.     Even
  4591. ; Note : magic title!
  4592. ; ~~~~~~~~~~~~~~~~~~~
  4593. ; If your extension begins with "MAGIC***", AMOSPro will call the 
  4594. ; address located after the string (even of course!). You can do whatever
  4595. ; you want to the editor screen (the current at the moment), but
  4596. ; restore it.
  4597. ; You also handle the user key press, and the PREVIOUS/NEXT/CANCEL
  4598. ; selection, buy returning a number in D0:
  4599. ;    D0=-1    Cancel
  4600. ;    D0=0    Previous extension
  4601. ;    D0=1    Next extension
  4602. ; Example of magic title:
  4603. ;    C_Title        dc.b    "MAGIC***"
  4604. ;            bra    Magic_Title
  4605.  
  4606.  
  4607. ; END OF THE EXTENSION
  4608. C_End    dc.w    0
  4609.     even
  4610.  
  4611.  
  4612.